Nidhin T T
Nidhin T T

Reputation: 298

Angular 2 : Error while using directive *ng-for

Just started working with Angular 2.0 beta version. I am getting error angular is not defined while adding directive : [angular.ngFor].

Adding the Plunker url http://plnkr.co/edit/ULHddLRqPFXvNG7NPo93?p=preview

Thanks in advance

Upvotes: 0

Views: 761

Answers (2)

Thierry Templier
Thierry Templier

Reputation: 202256

You don't need to specify the directive anymore since it's a core one. The name of the directive to use is ngFor instead of ng-for.

Your template:

<h2>{{teamName}}</h2>

<ul>
  {{players}}
  <li *ngFor="#player of players"> {{player}}</li>
</ul>

Your component:

(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 = {}));

Hope it helps you, Thierry

Upvotes: 3

G&#252;nter Z&#246;chbauer
G&#252;nter Z&#246;chbauer

Reputation: 657731

Since alpha.52 templates are case-sensitive. Use ngFor instead. This change also applies to other directives (ngIf, ngModel, ...)

Upvotes: 1

Related Questions