[英]Ng-style not working
我一直在尝试使用ng-style
但是它没有按预期工作。 在我的指令中,我做了类似的事情:
this.width = this.width+'px';
scope.myStyle = {width: this.width};
在我的html中,我有:
<div ng-style="myStyle" class="no-margin"
style="position:absolute;">
ng-style
应该包含一个对象,因此将代码更改为此:
this.width = this.width+'px';
scope.myStyle = {width: this.width, position:'absolute'};
<div ng-style="myStyle" class="no-margin">
方式应该是:
<div ng-style="{{ myStyle }}" class="no-margin">
原因是{{ }}
是AngularJs确定哪个是可变文本还是硬文本的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.