Angular2 @Input to a property with get/set

前端 未结 4 1210
故里飘歌
故里飘歌 2020-11-30 19:58

I have an Angular2 component in that component it currently has a bunch fields that have @Input() applied before them to allow binding to that property, i.e.



        
4条回答
  •  独厮守ぢ
    2020-11-30 20:27

    @Paul Cavacas, I had the same issue and I solved by setting the Input() decorator above the getter.

      @Input('allowDays')
      get in(): any {
        return this._allowDays;
      }
    
      //@Input('allowDays')
      // not working
      set in(val) {
        console.log('allowDays = '+val);
        this._allowDays = val;
      }
    

    See this plunker: https://plnkr.co/edit/6miSutgTe9sfEMCb8N4p?p=preview

提交回复
热议问题