首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Angularjs -无法将变量传递给指令

Angularjs -无法将变量传递给指令
EN

Stack Overflow用户
提问于 2015-04-29 19:54:27
回答 1查看 433关注 0票数 1

我有下面的代码。即使值是在第二行定义的,predictions['Team1 expected goals']在donutChart.js指令中也是作为undefined出现的。我如何正确地将其传递给指令?

代码语言:javascript
复制
<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>

以下代码的工作方式与预期一致:

代码语言:javascript
复制
<donut-chart team1="1.26" team2="0.81"></donut-chart>

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

代码语言:javascript
复制
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);
}
}
EN

回答 1

Stack Overflow用户

发布于 2015-05-28 21:42:40

在队伍中,

代码语言:javascript
复制
console.log('donutChart - team1: ' + scope.tea1 + ', team2: ' + scope.team2);

scope.tea1中有一个拼写错误,它应该是$scope.team1,因为作用域上没有属性tea1

它应该是

代码语言:javascript
复制
console.log('donutChart - team1: ' + scope.team1 + ', team2: ' + scope.team2);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29942973

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档