繁体   English   中英

NG样式不起作用

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM