angularjs - Angular: Evaluating a function on controller scope then passing it to a directive -
i'm trying evaluated function on parent controller send directive. need values watched digest loop , updated when user updates them.
i've worked through original issues, having problem getting bindings update.
i have controller object , function checks if object has values, returns true or false:
this.foo = { obj1: { name: '', time: 'time2' }, obj2: { name: 'name2', time: 'time2' } }; this.ispanecomplete = function(tab) { var finish = true; var tab2 = tab.tab; (var prop in tab2) { if (tab2.hasownproperty(prop)) { finish = !!tab2[prop] && complete; } } homecoming complete; };
i have directive called mypane scope :
scope: { completed : '&mypanecomplete' },
this template:
<my-pane my-pane-complete="gigeditctrl.ispanecomplete({tab : gigeditctrl.foo.obj1})"> <input type="text" placeholder="2014-12-31" ng-model="gigeditctrl.foo.obj1.name"> <input type="text" placeholder="2014-12-31" ng-model="gigeditctrl.foo.obj1.time">
when running next console.log true or false in directive
link: function(scope, element, attrs, tabsctrl) { console.log(scope.completed()); },
this works great. however, when update values in input boxes controller function isn't run 1 time again , console.log isn't fired. thoughts?
the solution issue utilize $watch
in directive , this
testapp.directive('mydir', function(){ return{ scope:{ test: '&' }, link: function(scope, el, attrs){ scope.$watch(scope.test, function(newvalue){ console.log('from dir name = '+ newvalue); }); } }; });
basically you utilize $watch
watch changes in homecoming value of function.
i've setup working demo here http://plnkr.co/edit/gk2tiltql8nw1qkvvrrk?p=preview
angularjs angularjs-directive angularjs-scope
No comments:
Post a Comment