【发布时间】:2017-06-07 12:15:19
【问题描述】:
我正在使用 atom 并且我的 ul 和 *ngFor 出现错误,我不明白为什么。我尝试四处搜索,但似乎无法找出我在所有 *ng 内容以及我的 ul 上都出现错误的原因。似乎没有出现 html 标签。
import { Component } from '@angular/core';
@Component({
selector: 'user',
template: `<h1>Hello {{name}}</h1>
<p><strong>Email</strong>: {{email}}</p>
<p>Address:{{address.street}} {{address.city}}, {{address.state}}</p>
<button (click) = "toggleHobbies()">Show Hobbies</button>
<div *ngIf = 'showHobbies'>
<h3>Hobbies</h3>
<ul>
<li *ngFor="let hobby of hobbies">
{{hobby}}
</li>
</ul>
</div>
`,
})
export class UserComponent {
name: string;
email: string;
address : address;
hobbies: string[];
showHobbies: boolean;
constructor(){
this.name = 'Richard';
this.email = 'Rjime061@fiu.edu'
this.address = {
street : '12 Main St.',
city : 'Boston',
state : 'MA'
}
}
this.hobbies = ['Music', 'Movies', 'Sports'];
this.showHobbies = false;
}
interface address {
street: string;
city: string;
state: string;
}
【问题讨论】:
-
请提供您收到的准确错误消息,以及有关您的应用程序行为异常的任何其他信息,例如浏览器中的显示。
-
当然,我现在刚刚提供了我的整个代码。我的 *ngIf 和 *ngFor 以及我的 ul 标签上仍然出现错误
-
代码不错,但请分享错误信息。顺便说一句,
this.hobbies =和this.showHobbies行——也许它们应该进入构造函数?它们现在所在的位置会导致编译错误。