2015-04-29 70 views
1

我有下面的代碼。 predictions['Team1 expected goals']在donutChart.js指令中出現爲undefined,即使該值是在第二行中定義的。我如何正確地將它傳遞給指令?如預期Angularjs - 不能將變量傳遞給指令

<div> 
    <div>{{ (fixture.team1.name.short_name || fixture.team1.name.gsm_name) }}</div> 
    <div>{{ predictions['Team1 expected goals'] | number : 2 }}</div> 
</div> 
<div> 
    <donut-chart team1="predictions['Team1 expected goals']" 
       team2="predictions['Team2 expected goals']"> 
    </donut-chart> 
</div> 

以下工作:

<donut-chart team1="1.26" team2="0.81"></donut-chart> 

下面是donutChart.js指令代碼。還要注意的是,結構是一個總體控制器調用一個指令(叫做models-prices),它調用這個圖表指令。

angular.module('stratabet') 
.directive('donutChart', function(appVersion) { 
    'use strict'; 

    var directive = { 
    priority: 0, 
    restrict: 'E', 
    scope: { 
     team1: '=', 
     team2: '=' 
    }, 
    controller: function($scope) { 
     console.log('donutChart controller - team1: ' + $scope.team1 + ', team2: ' + $scope.team2); 
    }, 
    link: function(scope, element, attrs) { 
     console.log('donutChart - team1: ' + scope.tea1 + ', team2: ' + scope.team2); 
} 
} 
+0

這確實看起來像l由於某種原因,ike CSS。 – Chris

+0

它在html模板中:http://jade-lang.com/ – user1387717

+0

你可以製作[jsfiddle.net](http://jsfiddle.net)嗎? – rcdmk

回答

0

在行,

console.log('donutChart - team1: ' + scope.tea1 + ', team2: ' + scope.team2); 

存在scope.tea1一個錯字,應該是$ scope.team1上仍然有範圍沒有財產TEA1

它應該是

console.log('donutChart - team1: ' + scope.team1 + ', team2: ' + scope.team2);