angular - 错误类型错误:无法读取未定义的属性“街道”
问题描述
我从 angular 开始,并在 YouTube 上遵循一个简单的教程。当我尝试在浏览器中显示代码时,出现以下错误:
错误类型错误:无法读取未定义的属性“街道”
这是代码:
import { Component } from '@angular/core';
@Component({
selector: 'user',
template: `
<h1>Hello {{name}}</h1>
<p><strong>Email:</strong> {{email}}</p>
<p><strong>Address:</strong> {{adress.street}}, {{adress.city}}, {{adress.state}}</p>
<button (click)= "toggleHobies()"> Show Hobbies</button>
<div *ngIf= "showHobies">
<h3>Hobies:</h3>
<ul>
<li *ngFor= "let hobby of hobbies">
{{hobby}}
</li>
</ul>
</div>
`,
})
export class UserComponent {
name: string;
email: string;
address: address;
hobbies: string[];
showHobies: boolean;
constructor() {
this.name = 'John Doe';
this.email = 'John@gmail.com'
this.address = {
street: '12 Main st',
city: 'Boston',
state: 'MA',
}
this.hobbies = ['Music', 'Movies', 'Sports'];
this.showHobies = false;
}
toggleHobies() {
if (this.showHobies == true) {
this.showHobies = false;
}
else {
this.showHobies = true;
}
}
}
interface address {
street: string;
city: string;
state: string;
}
我试图寻找答案,但找不到任何对我有帮助的东西。你能告诉我为什么会这样吗?
谢谢
解决方案
您在标记上输入错误的属性名称
adress -> address
推荐阅读
- git - 直接从 Visual Studio Code 编辑 GitHub 文档
- python - 以矢量图的形式绘制一组向量
- python - 异常值:NOT NULL 约束失败:send_appdata.product_id_id
- java - 在java正则表达式中如何捕获正斜杠后跟.(点)
- java - 为什么具有可完成未来的代码比并行流慢?
- jpa - FROM 子句中未定义标识变量“名称”
- java - 在 JavaFX 的 FXML 中,如何声明自定义事件的处理程序?
- kubernetes - 如何使用标签选项删除多个命名空间
- android - Android 应用在 Firebase UI 上崩溃 Facebook 登录
- angular - Angular Material点击下个月或上个月不起作用