双向绑定属性指令

时间:2016-08-10 13:36:29

标签: javascript angularjs twitter-bootstrap

我需要在bootstrap提供的progressBar指令的属性中进行双向数据绑定。

在progressBar组件中,我们有以下内容

.constant('uibProgressConfig', {
  animate: true,
  max: 100
})

当我在我的HTML中使用它时,我有这个。

<uib-progress ng-repeat="bar in myCtrl.stacked track by $index" animate="myCtrl.isRunning" value="{{bar.value}}" type="{{bar.type}}"
      style="width:{{myCtrl.percentage}}%; border-right: 1px solid #000; border-radius: 0px">

我想要的是具有双向数据绑定的动画值属性。

animate="myCtrl.isRunning"

问题在于我无法使用

animate={{myCtrl.isRunning}}

因为我收到了错误

  

错误:$ parse:syntax语法错误语法错误:令牌&#39; {&#39;表达式[{{field}}。$ error]第2列的无效键,从[{field}}开始。$ error]。

无论如何都要绑定这个属性&#34; animate&#34;一个模特?

1 个答案:

答案 0 :(得分:1)

初始化指令控制器时,animate属性看起来只有一次。它既不是$watched也不是$observed

来自ui-bootstrap.js :: UibProgressController

animate = angular.isDefined($attrs.animate) ? $scope.$parent.$eval($attrs.animate) : progressConfig.animate; 

您可能需要分叉模块并在$attrs.$observe('animate', setAnimate)

中添加UibProgressController