相关疑难解决方法(0)

无法绑定到'ng-forOf',因为它不是已知的本机属性

我想在这里遵循基本的Angular 2教程:

https://angular.io/docs/js/latest/guide/displaying-data.html

我可以使用以下代码加载角度应用并显示我的名字:

import { Component, View, bootstrap } from 'angular2/angular2';

@Component({
    selector: "my-app"
})

class AppComponent {
    myName: string;
    names: Array<string>;
    constructor() {
        this.myName = "Neil";

    }

}
bootstrap(AppComponent);
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试添加一个字符串数组并尝试使用ng-for显示它们时,它会抛出以下错误:

Can't bind to 'ng-forOf' since it isn't a known native property ("
    <p>Friends:</p>
    <ul>
        <li [ERROR ->]*ng-for="#name of names">
        {{ name }}
        </li>
"): AppComponent@4:16
Property binding ng-forOf not used by any directive on an embedded template ("
    <p>Friends:</p>
    <ul>
        [ERROR ->]<li *ng-for="#name of names">
        {{ name }} …
Run Code Online (Sandbox Code Playgroud)

angular

89
推荐指数
5
解决办法
6万
查看次数

*ngFor在角度2中不起作用

app.module.ts

import { NgModule }       from '@angular/core';
import { BrowserModule }  from '@angular/platform-browser';
import { FormsModule }    from '@angular/forms';
import { AppComponent }         from './app.component';
import { routing }  from './app.routing';
import { HttpModule, JsonpModule } from '@angular/http';
import { LoginComponent }       from './auth/login.component';
import { SignupComponent }       from './register/signup.component';

import { HomeComponent }    from './home/home.component';
import { SpinnerComponent} from './uiComponents/page-spinner/Spinner-Component';
import { SpinnerService} from './uiComponents/page-spinner/spinner-service';
import { authProviders }  from './auth/auth.providers';
import { LocalStorageService} from './state/local-storage.service';
import {CommonModule} from …
Run Code Online (Sandbox Code Playgroud)

angular2-directives angular2-template angular

5
推荐指数
1
解决办法
1万
查看次数