javascript - access scope variable from directive by name, avoiding using eval -
i'm new angularjs , currently working example(fiddle) doesn't feel right. when try blur field should increment event.times
, doing $apply
on line 10, i'm asking there better way achieve ? maybe var times = scope.$get(attrs.timesfield);
, scope.$apply(function(){ times += 1; });
whenever directive not use isolate scope , specify scope property using attribute, , want change value of property, use $parse:
<input custom-field times-field="event.times" ng-model="event.title" type="text">
link: function (scope, element, attrs){ var model = $parse(attrs.timesfield); element.bind('blur', function(){ model.assign(scope, model(scope) + 1); scope.$apply(); }); }
Comments
Post a Comment