大佬教程收集整理的这篇文章主要介绍了angular2 – 角度2.0绑定值到样式,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
import {Component,TemplatE} from 'angular2/angular2'; @Component({ SELEctor: 'circle',bind:{ "color":"color" } }) @Template({ url: System.baseURL + "/components/circle/template.html",}) export class Circle { constructor(){ } changeBACkground():string{ return "BACkground-color:" + this.color + ";"; } }
我的模板:
<style> .circle{ width:50px; height: 50px; BACkground-color: lightgreen; border-radius: 25px; } </style> <div class="circle" [style]="changeBACkground()"> <content></content> </div>
该组件的用法:
<circle color="teal"></circle>
我的绑定不起作用,但也不会抛出任何异常。
如果我将{{ChangeBACkground()}}放在模板的某处,那么会返回正确的字符串。那么为什么风格绑定不起作用?
还可以想到它,我如何看到Circle类内的颜色属性的更改?什么是替代品?
$scope.$watch("color",function(a,b,){});
在角2.0?
以上是大佬教程为你收集整理的angular2 – 角度2.0绑定值到样式全部内容,希望文章能够帮你解决angular2 – 角度2.0绑定值到样式所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。