AngularJS ng Options指令等待渲染

时间:2015-03-23 20:04:52

标签: angularjs directive ng-options

我的模板中已经使用ngOptions生成了选择列表。

<select class="dropdown" ng-options="price.weight for price in pricelist | unique: 'weight'" ng-model="weightModel" ng-change="updateWeight()" load-select="ngRepeatFinished"></select>

我使用此指令等待渲染列表

.directive('loadSelect', function($timeout){
    return{
        restrict: 'A',
        link: function(scope, element, attrs) {
        $timeout(function() {
            scope.$emit('ngRepeatFinished');
        });
        }
    }
})

想法是在选择列表完全呈现后运行一些js

$scope.$on('ngRepeatFinished', function(ngRepeatFinishedEvent) {
            console.log('rendered')
              $('.dropdown')
                .dropdown({
                    transition: 'drop'
                })
            ;
        });

有时它有效,机器人有时没有。它的工作量约为5倍。我做错了什么?

EDIT。现在我发现,如果浏览器中的控制台关闭,它根本不起作用(

0 个答案:

没有答案