我有一个带有setter / getter的setting
对象,用于计算字段setting.addressbits
。
$scope.setting = {
address:'111111',
get addressbits() {
return this.address.split('').map(Number);
},
set addressbits(val){
this.address = val.join('');
}
};
将其传递给双向绑定自定义指令。对象的getter
似乎每次返回一个新对象,其角度不喜欢as explained
.directive("bitField", function(){
return {
scope:{
bits: "="
},
template: '<div>custom directive</div>'
}
});
<bit-field bits="setting.addressbits"><</bit-field>
我该怎么做?