Carl Rippon

Building SPAs

Carl Rippon
BlogBooks / CoursesAbout
This site uses cookies. Click here to find out more

Angular Directive Case?

December 28, 2015
angulartypescript

I have been (and still a bit) confused about the case of angular 2’s directives … is it *ngFor or *ng-for … ie camel case or dash case? I’ve always used dash case in the alpha’s of Angular 2. However, the docs suggests camel case … but then the working example in this doc suggests dash case … angular2dashcase Confusing!

I decided to do a test rig myself on the latest version of Angular 2 (beta 0) …

camelCase

The following component works fine:

import { Component } from "angular2/core";

@Component({
  selector: "my-app",
  template: '<div *ngFor="#person of people">{{person.name}}</div>'
})
export class AppComponent {
  public people = [
    { id: 11, name: "John Smith" },
    { id: 12, name: "Fred Jones" },
    { id: 13, name: "Bob Peters" }
  ];
}

dash-case

However, the following component errors:

import { Component } from "angular2/core";

@Component({
  selector: "my-app",
  template: '<div *ng-for="#person of people">{{person.name}}</div>'
})
export class AppComponent {
  public people = [
    { id: 11, name: "John Smith" },
    { id: 12, name: "Fred Jones" },
    { id: 13, name: "Bob Peters" }
  ];
}

You get: Template parse errors: Can’t bind to ‘ng-forOf’ since it isn’t a known native property

So, it looks like we’re using camel case now in Angular 2 beta but the live examples still need to catch up …


Comments

Gopike March 14, 2018

Such a Nice explanation about the Directives. By reading your article, Anyone can easily understand. Very Good Article, Thank you so much for sharing it. Really it will be helpful for others. Also you can find latest topics in Angular 4 here

If you to learn more about TypeScript, you may find my free TypeScript course useful:

Learn TypeScript

Learn TypeScript
Take a look

Want more content like this?

Subscribe to receive notifications on new blog posts and courses

Required
© Carl Rippon
Privacy Policy