मैं स्थापित करने के लिए मेरी कक्षा (विशेषता बाध्यकारी द्वारा अधिग्रहीत) से एक रंग संपत्ति बाध्य करने के लिए कोशिश कर रहा हूँ background-colorमेरी की 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कक्षा के अंदर रंग की संपत्ति में परिवर्तन कैसे देखूंगा? के लिए प्रतिस्थापन क्या है
$scope.$watch("color", function(a,b,){});
कोणीय 2 में?
<div class="circle" [style.background]="'color'">