【发布时间】:2016-01-11 10:12:10
【问题描述】:
刚开始使用 Angular 2.0 测试版。添加 directive : [angular.ngFor] 时出现错误 angular is not defined。
添加 Plunker 网址http://plnkr.co/edit/ULHddLRqPFXvNG7NPo93?p=preview
提前致谢
【问题讨论】:
标签: angular angular2-directives
刚开始使用 Angular 2.0 测试版。添加 directive : [angular.ngFor] 时出现错误 angular is not defined。
添加 Plunker 网址http://plnkr.co/edit/ULHddLRqPFXvNG7NPo93?p=preview
提前致谢
【问题讨论】:
标签: angular angular2-directives
您不再需要指定指令,因为它是核心指令。要使用的指令名称是 ngFor 而不是 ng-for。
您的模板:
<h2>{{teamName}}</h2>
<ul>
{{players}}
<li *ngFor="#player of players"> {{player}}</li>
</ul>
你的组件:
(function(app) {
app.AppComponent =
ng.core.Component({
selector: 'my-app',
templateUrl: 'app/home.html',
})
.Class({
constructor: function() {
this.teamName = 'ManchesterUnited';
this.players = ['Ronney','Mata','Depay','Jhones','Smalling','Schiderlin'];
}
});
})(window.app || (window.app = {}));
希望对你有帮助, 蒂埃里
【讨论】:
由于 alpha.52 模板区分大小写。请改用ngFor。此更改也适用于其他指令(ngIf、ngModel、...)
【讨论】: