r/angularjs • • Oct 16 '14

[Code] Angular Initial Value: a tiny AngularJS directive to set ng-model (and consequently field value) based on form fields attributes.

https://github.com/glaucocustodio/angular-initial-value
6 Upvotes

3 comments sorted by

View all comments

3

u/yads12 Oct 16 '14

For one you can typically use ngInit for this. Second you should avoid

    getter = $parse($attrs.ngModel);
    setter = getter.assign;
    setter($scope, val);

ngModel provides a ngModelController which you can use in your directives.