admin管理员组文章数量:1332377
i got a very weird situation here.
At first, I wrote a simple directive.
mublABase.directive('parentSize', function() {
return {
link : function(scope, elem, attrs) {
scope.parentSize = {
width : elem.parent().width(),
height : elem.parent().height()
}
}
}
});
And this is my simplified html code
<input type="text" ng-model="parentSize.width"> //for test No.1
<div parent-size class="no-border">
{{parentSize.width}} //for test No.2
<span class="glyphicon glyphicon-leaf" ng-style="{'font-size':'{{parentSize.width}}px'}"></span> //this is the problem No.3
</div>
And result is broken. No.1 input and No.2 text says width is 285. But at No.3, that leaf icon's size is just default size.
(Sorry for not posting result image. I'm very noob here and i don't have any reputation)
How can it happened? And much importantly, how can i solve it?
i got a very weird situation here.
At first, I wrote a simple directive.
mublABase.directive('parentSize', function() {
return {
link : function(scope, elem, attrs) {
scope.parentSize = {
width : elem.parent().width(),
height : elem.parent().height()
}
}
}
});
And this is my simplified html code
<input type="text" ng-model="parentSize.width"> //for test No.1
<div parent-size class="no-border">
{{parentSize.width}} //for test No.2
<span class="glyphicon glyphicon-leaf" ng-style="{'font-size':'{{parentSize.width}}px'}"></span> //this is the problem No.3
</div>
And result is broken. No.1 input and No.2 text says width is 285. But at No.3, that leaf icon's size is just default size.
(Sorry for not posting result image. I'm very noob here and i don't have any reputation)
How can it happened? And much importantly, how can i solve it?
Share Improve this question asked Dec 4, 2014 at 3:51 MoonriseMoonrise 1131 silver badge7 bronze badges 1-
1
ng-style="{ 'font-size' : parentSize.width }"
– tymeJV Commented Dec 4, 2014 at 3:55
1 Answer
Reset to default 8You have just got your ng-style
syntax confused.
The value for each of the properties of the object in ng-style
is an AngularJS expression, which means you can refer directly to scope properties.
Change it to ng-style="{'font-size': parentSize.width + 'px'}"
.
本文标签: javascriptAngular scope39s variable from directive not syncing in ngstyleStack Overflow
版权声明:本文标题:javascript - Angular scope's variable from directive not syncing in ng-style - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742305461a2449825.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论