AngularJS ng-model should have a dot

Posted in Tutorials

Tweet This Share on Facebook Bookmark on Delicious Digg this Submit to Reddit

In our previous tutorial, we have …

ng-model without the dot

ng-model without the dot

See that ng-model=”itemToAdd” does not have a dot in it.

The AngularJS way is to have a dot somewhere in the value of the ng-model as in …

ng-model=”data.itemToAdd”

ng-model with the dot

ng-model with the dot

The use of “data” is arbitrary.  You can use ng-model=”prop.itemToAdd” if you like.

While in our simple example, the app works either way.  There are cases where it may not.  For example, take a look at this tutorial as an aside.

It is a good habit to learn to put a dot in the ng-model because in more complex cases, things may not work without the dot.  Egghead.io has a video explaining.

Continue to next tutorial.