在一个自定义指令中
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()函数实现,在指令渲染完成之后,执行需要执行的函数。