I have a question, code like this:
HTML:
<div class="overflow-hidden ag-center" world-data info="target"></div>
js:
.directive('worldData', ['$interval', function($interval) {
return {
scope: {
chart: '=info'
},
template: '<div>{{chart.aaa}}</div>',
link: function($scope, element, attrs) {
$scope.target = {'aaa': 'aaa'};
aaa = $scope.chart;
}
}
}])
The chart value is undefined, and template no value, but when I declare $scope.target within controller, the code works, why?
targetvalue on the parent scope of the directive. The link function isn't doing anything that should affect the rendered values, as far as I can see.link: function($scope, element, attrs) { $scope.target = {'aaa': 'aaa'}; $scope.chart = $scope.target; }DOM render immediately. And the code works perfectlychart: '=info'is for passing in data from outside the directive. In this case you're passingtarget(should be defined outside the directive, presumable in a controller) to the directive viainfowhich maps to the directive's$scope.chart. Are you defining target as the appropriate data outside the directive to be passed in?scope:{chart: '=info'}is specifically only for passing in a value from outside the directive to inside the directive, mapped via an attribute, in this case a value passed intoinfo=""will be mapped to$scope.chartinside your directive. If you want to define the value inside the directive, then do that, either inlinkorcontroller, and just havescope:{}in the directive definition.