我整个上午都在尝试使用ng-style,但是它并没有像预期的那样工作。在我的指令中,我做了类似的事情:
this.width = this.width+'px';
scope.myStyle = {width: this.width};在我的html中,我有:
<div ng-style="myStyle" class="no-margin"
style="position:absolute;">发布于 2015-04-14 23:25:43
ng-style应该包含一个对象,因此将您的代码更改为:
this.width = this.width+'px';
scope.myStyle = {width: this.width, position:'absolute'};
<div ng-style="myStyle" class="no-margin">发布于 2017-02-05 00:01:44
方法应该是:
<div ng-style="{{ myStyle }}" class="no-margin">
原因是{{ }}是AngularJ确定变量或硬文本的方式。
https://stackoverflow.com/questions/29631141
复制相似问题