I'm trying to bind a color property from my class (acquired by attribute binding) to set the background-color
of 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 + ";";
}
}
My template:
<style>
.circle{
width:50px;
height: 50px;
background-color: lightgreen;
border-radius: 25px;
}
</style>
<div class="circle" [style]="changeBackground()">
<content></content>
</div>
The usage of this component:
<circle color="teal"></circle>
My binding is not working, but doesn't throw any exceptions either.
If I would put {{changeBackground()}}
somewhere in the template, that does return the correct string.
So why is the style binding not working?
Also, how would I watch the changes to the color property inside the Circle
class? What is the replacement for
$scope.$watch("color", function(a,b,){});
in Angular 2?