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();    }); } 

fiddle


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -