指令中不可访问angularjs范围
我正在尝试使用angularjs指令加载图表。我想在数据来自服务器响应后加载图表。但范围是空的。我的代码是指令中不可访问angularjs范围,angularjs,angularjs-directive,angularjs-scope,Angularjs,Angularjs Directive,Angularjs Scope,我正在尝试使用angularjs指令加载图表。我想在数据来自服务器响应后加载图表。但范围是空的。我的代码是 <div class="span4" ui-if="loadingIsDone"> <article id="piChart2"> <section id="toolBox1"&
<div class="span4" ui-if="loadingIsDone">
<article id="piChart2">
<section id="toolBox1">
<h3 id="toolH1"></h3>
<p id="toolD1"></p>
</section>
<article id="toolTip1"></article>
<canvas id="canvas1" width="250" height="250" draw-chart>
</canvas>
</article>
</div>
我的指令是
Directives.directive('drawChart', function() {
return function(scope, element, attrs) {
console.debug("element :"+element);
console.debug("attrs :"+attrs);
graphDraw('canvas1',scope.teamStrengths.value1,scope.teamStrengths.value2,scope.teamStrengths.value3)
//grap loads successfully with static data
};
});
请帮助我,我将非常感谢(
$http
呼叫是异步的。指令需要在范围内$watch
更改。在指令中添加以下内容:
scope.$watch('teamStrengths', function(newValue, oldValue) {
if (newValue)
graphDraw('canvas1',scope.teamStrengths.value1,scope.teamStrengths.value2,scope.teamStrengths.value3)
}, true);
或监视$scope.LoadingIsOne
更改:
scope.$watch('loadingIsDone', function(newValue, oldValue) {
if (newValue == true)
graphDraw('canvas1',scope.teamStrengths.value1,scope.teamStrengths.value2,scope.teamStrengths.value3)
}, true);
$http
调用是异步的。指令需要在范围内$watch
更改。在指令中添加以下内容:
scope.$watch('teamStrengths', function(newValue, oldValue) {
if (newValue)
graphDraw('canvas1',scope.teamStrengths.value1,scope.teamStrengths.value2,scope.teamStrengths.value3)
}, true);
或监视$scope.LoadingIsOne
更改:
scope.$watch('loadingIsDone', function(newValue, oldValue) {
if (newValue == true)
graphDraw('canvas1',scope.teamStrengths.value1,scope.teamStrengths.value2,scope.teamStrengths.value3)
}, true);