如何将带有getter / setter的javascript对象传递给angular指令

时间:2016-02-10 17:02:06

标签: javascript angularjs

我有一个带有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>

live code here

我该怎么做?

0 个答案:

没有答案