angularjs directive指令 link在渲染完成之后执行

在一个自定义指令中

export default class {

    /*@ngInject*/
    constructor() {
        thi.restrict = 'E';
        this.scope = {
            ngSrc: '@'
        };
        this.template = `<div class="player" layout="column"  layout-align="center center" style="height:190px">
                            <div id={{id}} class="flowplayer">
                            </div>
                         </div>`;
    }
    link(scope, element, attrs, ngModelController) {
        scope.id = 'flow-player-' + Math.floor(Math.random()*10000);
        scope.init = function () {
            flowplayer(scope.id, FlowPlayerPlay, {
                clip: {
                    url:attrs.ngSrc ,
                    autoPlay: false,
                    autoBuffering: true
                }
            });

        };
        setTimeout(function(){
            scope.init();
        },0);

    }
}

  可以借用setTimeout()函数实现,在指令渲染完成之后,执行需要执行的函数。

posted @ 2017-05-10 14:54  拳拳  阅读(1321)  评论(0编辑  收藏  举报