directive Isolated Scope undefined, angularjs 1.3 -
i'm doing directive have unusual behavior when console on scope value passed controller scope printed, when seek access scope undefined scope.model
this code:
function() { var color = d3.interpolatergb('#f77', '#77f'); homecoming { template: '<div></div>', restrict: 'e', scope:{ model:'=' }, link: function postlink(scope, element, attrs) { console.log(scope); //print model console.log('scope.model ',scope.model); // undefined var width = attrs.width || 940, height = attrs.height || 500, margin = 20; var modeler = d3.select(element[0]) .append('svg') .attr('width', width) .attr('height', height); } }; }
html
<d3-directive model="model" width="920" height="510" ></d3-directive>
please take console output:
i ended adding $watch on value of scope , using new value assigned.
return { template: '<div></div>', restrict: 'e', scope:{ model:'=' }, link: function postlink(scope, element, attrs) { console.log(scope); console.log('scope.model ',scope.model); scope.$watch('model',function(newvalue,oldvalue){ if(!!newvalue){ console.log(newvalue); } }); var width = attrs.width || 940, height = attrs.height || 500, margin = 20; var modeler = d3.select(element[0]) .append('svg') .attr('width', width) .attr('height', height); } };
angularjs angular-directive
No comments:
Post a Comment