這是我的代碼angular2 ngFor不顯示數據
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-jobcompleted',
templateUrl: './jobcompleted.component.html',
styleUrls: ['./jobcompleted.component.scss']
})
export class JobcompletedComponent {
name: string;
email: string
address: string;
hobbies: string[];
showHobbies: boolean;
constructor(){
this.name = "john doe",
this.email = "[email protected]",
this.address = "ukay perdana"
this.hobbies= ['music','movies','sport'];
this.showHobbies = true;
}
tooggleHobbies(){}
}
我的模板
<h2>Hello {{ name }}</h2>
<h2>email : {{ email }}</h2>
<h2>address : {{ address }}</h2>
<h2>hobby</h2>
<ul>
<li ngFor="let hobby of hobbies">{{ hobby }}</li>
</ul>
但ngFor
不顯示任何數據:
我試着的代碼,但他們沒有很多風格的作品對我來說: -
<ul>
<li *ngFor="let hobby of hobbies">{{ hobby }}</li>
</ul>
<ul>
<li *ngFor="#hobby of hobbies">{{ hobby }}</li>
</ul>
<ul>
<li ngFor="#hobby of hobbies">{{ hobby }}</li>
</ul>
我的代碼有什麼問題?這是我的角度版本
@angular/cli: 1.0.0-beta.31
node: 6.9.2
os: win32 x64
@angular/common: 2.4.7
@angular/compiler: 2.4.7
@angular/core: 2.4.7
@angular/forms: 2.4.7
@angular/http: 2.4.7
@angular/platform-browser: 2.4.7
@angular/platform-browser-dynamic: 2.4.7
@angular/router: 3.4.7
@angular/cli: 1.0.0-beta.31
@angular/compiler-cli: 2.4.7
我只是想'
有沒有錯誤?圖片顯示一個點,所以「li」顯示正確?開發工具中元素的外觀如何?上面的列表中添加''
以確保上下文有你期望 –