我需要申请多的CSS规则HTML标签中的角表单模板。
I need for apply multi css rule to html tag in angular form template.
<div class="form-control" id="data.objectStyle"
ng-model="data.type"
ng-style="getStyle(data.objectStyle)">
{{data.objectStyle.title}}
</div>
在控制器的getStyle功能:
getStyle function in controller :
$scope.getStyle = function (taskType) {
return {
background-color:taskType.backColor,
color: taskType.color,
font-size:taskType.fontSize,
font-family:taskType.font
}
)};
任务类型的对象:
taskType object:
{
backColor:'#006',
color:'#56DA',
fontSize:12,
font:'New Times Roman'
}
的的getStyle
函数不返回一个风格!怎么办?
The getStyle
function does not return a style! What to do?
借助文档指定你需要用你的钥匙放在引号如此他们不是无效的JSON对象键:
The docs specify that you need to wrap your keys in quotation marks so they aren't invalid JSON object keys:
return {
"background-color": taskType.backColor,
"color": taskType.color,
"font-size":taskType.fontSize,
"font-family":taskType.font
}
虽然我从来没有使用过 NG式,它似乎并没有采取的对象。相反,它是纳克级的,但单风格等效。
While I never used ng-style, it doesn't seem to take objects. Rather it is an equivalent of ng-class but for single styles.
试着改变你的功能:
$scope.getStyle = function (taskType) {
return {
"background-color:"+taskType.backColor+
";color:"+ taskType.color+
";font-size:"+taskType.fontSize+
";font-family:"+taskType.font+";";
}
)};
和使用常规的风格标签用绑定在html:
and the html to use the regular style tag with a bind:
<div class="form-control" id="data.objectStyle" ng-model="data.type" style="{{getStyle(data.objectStyle)}}">
上一篇:预输入角度UI - 无法读取未定义的属性“长度”长度、属性、角度、未定义
下一篇:ngOptions&QUOT;跟踪由&QUOT;前pressionngOptions、QUOT、pression