2017-06-07 24 views
0

「ngForは動作していません」というほとんどの質問を終えました。以下はその詳細です。* ngForは動作しません。コンソールにエラーはありません

app.modules.ts

import { NgModule } from '@angular/core';  
import { BrowserModule } from '@angular/platform-browser';  
import { TweetComponent } from './tweet.component';  
import { AppComponent } from './app.component'; 

@NgModule({  
    imports: [BrowserModule], 
    declarations: [AppComponent, TweetComponent], 
    bootstrap: [AppComponent] 
    }) 

export class AppModule { } 

app.components.ts

import { Component } from '@angular/core'; 
import { CommonModule } from "@angular/common"; 

@Component({ 
    selector: 'my-app', 
    template: `<h1>List of tweets</h1> 
      <tweets><tweets>`, 
}) 

export class AppComponent { name = 'Angular'; } 

tweet.component.ts

import { Component } from "@angular/core" 
@Component({ 
    selector: 'tweets', 
    template: `<ul> 
       <li *ngFor="let item of myList"> 
        <span> {{ item}}</span> 
        </li> 
       </ul> ` 
}) 

export class TweetComponent { 
     myList: ['.net', 'C#', 'web services']; 
} 

出力:

Output

要素:

Elements

とコンソールにエラーがあります。

答えて

2

それはあなたが:を使用している場合、それはフィールドの型を宣言しようとします

myList = ['.net', 'C#', 'web services']; 

してきたはずです。

例:

myList: Array<string> = ['.net', 'C#', 'web services']; 
2

あり=

myList= ['.net', 'C#', 'web services']; 

を使用して割り当てる必要があり、配列はmyListで二つの問題、

値があり、あなたは、テンプレート上のタグを逃しています

@Component({ 
    selector: 'my-app', 
    template: `<h1>List of tweets</h1> 
      <tweets></tweets>`, 
}) 
関連する問題