This website uses cookies to allow us to see how the site is used. If you continue to use this site we will assume that you are happy with this.Click to hide
Menu
CoDE - NCR Edinburgh
CoDE - NCR Edinburgh
  • Home
  • People
  • Events
  • Social
  • Products
  • Jobs
  • Edinburgh
  • Blog
  • Contact
 home > blog > angular getters setters

ng-model with native getters and setters

Within this Video Phil speaks about ng-model with native getters and setters.

When using Angular it is best to use fat models, thin controllers, put our business logic in factories and prefer functions over properties. However ng-model can only bind to properties, so we find we do need to expose properties. Fortunately JavaScript allows us to define native getter and setter methods which are called implicitly when we get or set properties. This allows us to apply constraints to values in the model rather than in the digest cycle.

Note Angular 1.3 adds the concept of binding ng-model to custom getter/setters which you can use in place of the native getter/setters described above.

http://plnkr.co/edit/aqV3DTAJNATPimA7hq0s?p=preview

ng-model with native getters and setters

https://docs.angularjs.org/api/ng/directive/ngModel#binding-to-a-getter-setter


Phil Holden
Tags: angular
October 10th 2014

  • Top
  • Home
  • People
  • Events
  • Social
  • Products
  • Jobs
  • Edinburgh
  • Blog
  • Contact
  • NCR Global
  • Home
  • NCR Global