简体   繁体   English

AngularJS:HTML属性中和内部的变量<style> markup

[英]Angularjs: variables in html attributes and within <style> markup

I would like to know how to put an angularjs model as the value for an html attribute. 我想知道如何将angularjs模型作为html属性的值。 such as: 如:

<div ng-controller="deviceWidth" width={{width}}> </div>

also, how would I do this within <style> markup? 另外,我该如何在<style>标记内执行此操作? Where would I put ng-controller? 我将把ng-controller放在哪里?

div {
    width:{{width}}
}

Thanks, Ben 谢谢,本

You'd better do create own custom directive instead of the "static" width , and interpret the interpolation with $observe function. 您最好创建自己的自定义指令,而不要创建“ static” width ,并使用$ observe函数解释插值。

Post pretty similar, involving some solutions: 发布非常相似,涉及一些解决方案:
String Interpolation Won't Work when Setting Attribute Values on a Custom Directive 在自定义指令上设置属性值时,字符串插值将不起作用

Concerning the markup, you'd better play with ng-class , whose value comes from your controller logic. 关于标记,最好使用ng-class ,其值来自控制器逻辑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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