Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.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/21.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
Angular ng repeat和jQuery插件_Jquery_Angularjs_Angularjs Directive_Angularjs Ng Repeat - Fatal编程技术网

Angular ng repeat和jQuery插件

Angular ng repeat和jQuery插件,jquery,angularjs,angularjs-directive,angularjs-ng-repeat,Jquery,Angularjs,Angularjs Directive,Angularjs Ng Repeat,我想变成一个有角度的指令。我做了以下工作: define(['directives/directives'], function(directives){ directives.directive('vivifysortable', ['$rootScope', function ($rootScope){ return { controller: function ($scope, $element, $attrs){ // here i pas

我想变成一个有角度的指令。我做了以下工作:

define(['directives/directives'], function(directives){
directives.directive('vivifysortable', ['$rootScope', function ($rootScope){
    return {
        controller: function ($scope, $element, $attrs){
            // here i pasted definition of multiselectable, 
            //and multisortable from the above jsfiddle
        },
        link: function($scope, $element, $attrs) {
            if ($scope.$last === true) {                    
                setTimeout(function() {
                        angular.element($element).multisortable({                            
                        connectWith: ".product-backlog-column",
                        selectedClass: "ui-selected"
                    });
                })
            }
         }   
    }
}]); 
});
如果我有这样的东西,这个很好用

 <ul class="product-backlog-column" vivifysortable >
    // some hardcoded values for testing purposes
    <li> test  1 </li>
    <li> test  2 </li>
    <li> test  3 </li>
 </ul>
看起来,ng repeat给我带来了困难,但我不知道为什么,以及如何解决


下面是解决这个问题的方法(我不确定我是否正确创建了它,包括Angular onLoad和jQuery作为外部资源)。

我通过添加
$timeout
解决了这个问题。重构后的代码如下所示:

 link: function($scope, $element, $attrs) {
            $timeout(function () {
                angular.element($element).multisortable({

                    connectWith: ".product-backlog-column",
                    selectedClass: "ui-selected"
                });
            }, 0);

  }   

问题是,
$timeout
将停止执行指令,直到
ng repeat
完成渲染。这是我初学者的解释。如果有更有经验的人能对此有更多的了解,请这样做。

我通过添加
$timeout
解决了这个问题。重构后的代码如下所示:

 link: function($scope, $element, $attrs) {
            $timeout(function () {
                angular.element($element).multisortable({

                    connectWith: ".product-backlog-column",
                    selectedClass: "ui-selected"
                });
            }, 0);

  }   

问题是,
$timeout
将停止执行指令,直到
ng repeat
完成渲染。这是我初学者的解释。如果有更有经验的人能更清楚地说明这一点,请这样做。

你能用同样的代码做一个小摆弄吗?我刚刚添加了JSFIDLE,请看一看你能用同样的代码做一个小摆弄吗?我刚刚添加了JSFIDLE,请看一看