【问题标题】:Angular 2 : Error while using directive *ng-forAngular 2:使用指令 *ng-for 时出错
【发布时间】: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


【解决方案1】:

您不再需要指定指令,因为它是核心指令。要使用的指令名称是 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 = {}));

希望对你有帮助, 蒂埃里

【讨论】:

    【解决方案2】:

    由于 alpha.52 模板区分大小写。请改用ngFor。此更改也适用于其他指令(ngIfngModel、...)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-01
      • 1970-01-01
      • 2017-03-07
      • 2016-08-17
      • 1970-01-01
      • 2017-02-02
      • 2017-06-11
      • 2021-08-07
      相关资源
      最近更新 更多