angular - VSCode 无法识别模板中的变量
问题描述
我正在学习名为 Learning AngularJS 2 的 Lynda 课程,并且我已经完成了让应用程序正常工作的任务。它可以正常编译并在浏览器中按预期工作。但是,Visual Studio Code在所有模板文件中都给了我问题警告:
未定义标识符“艺术家”。组件声明、模板变量声明和元素引用不包含这样的成员
艺术家详细信息.component.html:
<div class="container mt-3">
<div class="row justify-content-center">
<div class="col-sm-4 col-lg-3">
<img class="img-fluid rounded" src="assets/images/{{artist.shortname}}.jpg" alt="{{artist.name}} photo">
</div>
<div class="col-sm-8 col-lg-4">
<h2 class="mt-3 mt-sm-0 mb-0">{{artist.name}}</h2>
<h4 class="mt-0">{{artist.reknown}}</h4>
<p>{{artist.bio}}</p>
</div>
</div>
艺术家详细信息.component.ts:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-artist-details',
templateUrl: './artist-details.component.html',
inputs: ['artist']
})
export class ArtistDetailsComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}
我已经安装了Angular Essentials扩展。
解决方案
好吧,我发现它似乎是一个 Visual Studio Code 错误。写作artist['name']
而不是artist.name
使警告消失。
推荐阅读
- vb.net - 将图像拉伸到十六进制图片框
- react-native - React Native - 从水平选择器中获取价值
- java - 如何在 PDFBox 中将字符串保存为 PDF?
- sql - 如何查找超过 5 年期间超过设定金额的记录
- r - 在 R 中设置 Treemapify 子组颜色
- jira - 推送子任务到期日期时推送的父 JIRA 日期
- javascript - 如何使用 javascript 检查表单的数据,然后重定向到第二个 html 文件?
- javascript - emscripten-fastcomp 的 Longjmp 失败
- arduino - 带有 Platform.io 的 ESP8266 上的 ESP8266WebServer 编译错误
- reactjs - 为什么 usePrevious 在第一次渲染时返回 undefined - 反应钩子?