Angularjs - 不能将变量传递给指令

时间:2015-04-29 11:54:27

标签: angularjs angularjs-directive angularjs-scope

我有以下代码。 {* 1}}在donutChart.js指令中显示为predictions['Team1 expected goals'],即使该值是在第二行定义的。如何正确地将其传递给指令?

undefined

以下按预期方式运作:

<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>

这是donutChart.js指令的代码。另请注意,结构是,整体控制器调用一个指令(称为models-prices),该指令调用此图表指令。

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

1 个答案:

答案 0 :(得分:0)

在该行中,

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

scope.tea1 中存在拼写错误,它应该是 $ scope.team1 ,因为范围内没有属性tea1

应该是

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