Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/435.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Angular指令需要访问ng repeat中的变量_Javascript_Angularjs_Directive - Fatal编程技术网

Javascript Angular指令需要访问ng repeat中的变量

Javascript Angular指令需要访问ng repeat中的变量,javascript,angularjs,directive,Javascript,Angularjs,Directive,我有一种感觉,这件事我想得太多了。任何帮助都将不胜感激。谢谢 您应该更改HTML,以便将当前活动对象传递给指令: myApp.directive('progressbar', function(){ return { restrict: 'A', scope: { 'progress': '=progressbar' }, controller: function($scope, $element, $attrs) { $ele

我有一种感觉,这件事我想得太多了。任何帮助都将不胜感激。谢谢

您应该更改HTML,以便将当前活动对象传递给指令:

myApp.directive('progressbar', function(){
  return {
    restrict: 'A',
    scope: {
        'progress': '=progressbar'
    },
    controller: function($scope, $element, $attrs) {
        $element.progressbar({
            value: *** I want this to refer to the correct campaign.percent ***
        })
    }
  }
})

当然,您可以直接传递百分比值,但我认为提供完整的活动对象是有意义的,以防您需要百分比以外的其他属性。

您尝试过吗?Life saver!非常感谢!
myApp.directive('progressbar', function(){
  return {
    restrict: 'A',
    scope: {
        'progress': '=progressbar'
    },
    controller: function($scope, $element, $attrs) {
        $element.progressbar({
            value: *** I want this to refer to the correct campaign.percent ***
        })
    }
  }
})
<div ng-repeat="campaign in campaigns">
    <div progressbar="campaign"></div>
</div>
controller: function($scope, $element, $attrs) {
    $element.progressbar({
        value: $scope.progress.percent
    });
}