Bidirectional data binding on a component input property

前端 未结 4 1827
名媛妹妹
名媛妹妹 2021-02-19 07:24

I am trying to make something work on angular2 and I am unable to find something about this behavior.

I have an application that implements a custom component like this

4条回答
  •  感情败类
    2021-02-19 08:25

    What I do is use a property, so when I change the data the change is emitted automatically

    private _data: AnyType;
    @Input()  get data(): AnyType{
        return this._data;
    }
    set data(value: AnyType) {
        this._data = value;
        this.dataChange.emit(this._data);
    }
    @Output() dataChange: EventEmitter = new EventEmitter();
    

    In html you will bind the property using [(data)]

    
    

提交回复
热议问题