background-color
クラスから色プロパティをバインドして (属性バインディングによって取得) 、 myの を設定しようとしていdiv
ます。
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
また、クラス内の color プロパティの変更をどのように監視しますか? 代わりになるものは何ですか
$scope.$watch("color", function(a,b,){});
角度2で?