Javascript ng重复后的AngularJS Nanoscoller不';不显示

Javascript ng重复后的AngularJS Nanoscoller不';不显示,javascript,jquery,angularjs,scrollbar,angularjs-ng-repeat,Javascript,Jquery,Angularjs,Scrollbar,Angularjs Ng Repeat,我已经在stackoverflow上浏览了很多帖子,但我还没有找到答案。我有一个jQuery滚动条插件(nanoscroll),我希望它在ng重复之后更新。 正如这里的许多帖子所暗示的,我使用了这样一个指令: myApp.directive("postRender", function() { return function(scope, element, attrs) { jQuery('.nano').nanoScroller({preventPageScrollin

我已经在stackoverflow上浏览了很多帖子,但我还没有找到答案。我有一个jQuery滚动条插件(nanoscroll),我希望它在ng重复之后更新。 正如这里的许多帖子所暗示的,我使用了这样一个指令:

myApp.directive("postRender", function() {
    return function(scope, element, attrs) {
        jQuery('.nano').nanoScroller({preventPageScrolling: true});
    }
});
然后我有一些类似的东西:

<div class="nano"> <!-- my scrollable area -->
    <div ng-controller="MyController">
        <div ng-repeat="item in items" post-render>
        ...
        </div>
    </div>
    Some content here...
</div> <!-- my scrollable area -->

虽然我找到了一个解决方案,但我仍然没有意识到存在的问题。我相信这是因为angular指令没有等待DOM被完全修改,可能是时间问题

OP找到了解决方案

必须使用$timeout服务。像这样:

myApp.directive('postRender',['$timeout', function (timer) {
    return {
        link: function (scope, elem, attrs, ctrl) {
            timer(function () {
                    jQuery('.nano').nanoScroller({preventPageScrolling: true})    
                 }, 0);
        }
    }
}]);

最好将答案张贴为“答案”,并将其标记为答案:)
myApp.directive('postRender',['$timeout', function (timer) {
    return {
        link: function (scope, elem, attrs, ctrl) {
            timer(function () {
                    jQuery('.nano').nanoScroller({preventPageScrolling: true})    
                 }, 0);
        }
    }
}]);