Notify child component about changes in Angular2

前端 未结 2 1322
野性不改
野性不改 2021-01-02 01:34

Suppose I have simple Angular2 component

@Component({ selector: \'parent\' })
@View({
    template: `
        

        
2条回答
  •  醉酒成梦
    2021-01-02 01:41

    You can use getters and setters to manage it. For your example Child component must be looked like this:

    @Component({
      selector: 'child',
      properties : ['model']
    })
    @View({
      template: `
        

    Child {{ model }}

    `, }) class Child { _model: number; set model(newModelValue) { // Here we are console.log('new model value: ' + newModelValue) this._model = newModelValue; } get model() { return this._model; } }

    Here is the plunker for your case

提交回复
热议问题