angular @input get set

protected _isOpen = false;
@Input()
  get isOpen(): boolean {
    return this._isOpen;
  }

  set isOpen(value: boolean) {
    if (value !== this.isOpen) {
      if (value) {
        this.accordion.closeOtherPanels(this);
      }
      this._isOpen = value;
      Promise.resolve(null).then(() => {
        this.isOpenChange.emit(value);
      });
    }
  }

为了让_isOpen暴露出来便于修改 用set方法初始化_isOpen,用get方法获取内部私有变量修改

你可能感兴趣的:(angular @input get set)