【发布时间】:2017-01-22 12:18:25
【问题描述】:
我需要通过ng-style从配置对象设置元素的背景,但是由于某种未知原因我不能这样做,这对我来说真的很奇怪,我真的找不到原因。
我要配置的元素:
<div id="progress-l" ng-style="{ 'width': pblc.options.width, 'height': pblc.options.height, 'background': plbc.options.color }"></div>
pblc在这里代表控制器,我使用controllerAs选项
配置对象:
this.progressLOptions = {
color: '#F0F3F4',
width: '200px',
height: '20px',
};
最奇怪的是设置了宽度和高度,在渲染的html中我看到了:
<div id="progress-l" ng-style="{ 'width': pblc.options.width, 'height': pblc.options.height, 'background': plbc.options.color }" style="width: 200px; height: 20px;">
</div>
我真的不知道 ng-style 怎么会这样工作。我找不到背景是否有问题?
【问题讨论】:
-
pblc.options是什么,我看到你有progressLOptions,你把范围变量名弄乱了吗? -
@PankajParkar 不,我只是使用
controllerAs进行指令,如果是命名,高度和宽度也不会设置
标签: javascript html css angularjs ng-style