我有下面的代码。即使值是在第二行定义的,predictions['Team1 expected goals']在donutChart.js指令中也是作为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>以下代码的工作方式与预期一致:
<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);
}
}发布于 2015-05-28 21:42:40
在队伍中,
console.log('donutChart - team1: ' + scope.tea1 + ', team2: ' + scope.team2);scope.tea1中有一个拼写错误,它应该是$scope.team1,因为作用域上没有属性tea1
它应该是
console.log('donutChart - team1: ' + scope.team1 + ', team2: ' + scope.team2);https://stackoverflow.com/questions/29942973
复制相似问题