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

原创
半兽人 发表于: 2020-02-16   最后更新时间: 2020-02-16 21:46:19  
{{totalSubscript}} 订阅, 1,146 游览

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

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);
    }
}
更新于 2020-02-16

查看AngularJS更多相关的文章或提一个关于AngularJS的问题,也可以与我们一起分享文章