Angular

作者: LIsPeri | 来源:发表于2018-03-23 15:55 被阅读0次

页面上指令的属性为控制器(controller)$scope的值 如果在指令中要获取这个值,如果在link中用attr去获取,可能为underfind 是因为页面数据还没加载完成 最好的办法是在link中 用scope.$watch 去监听这个值。如下

function bookDetalis(){
return {
restrict: 'AEC',
replace: true,
scope:{
description:'@',
},
template:'<div>{{description}}</div>' ,
link: function(scope,elem,attrs) {
scope.$watch('description',function(){
if(scope.description){
console.log(elem[0].offsetHeight);
}
});
}
}
}

相关文章

网友评论

    本文标题:Angular

    本文链接:https://www.haomeiwen.com/subject/nmsxcftx.html