Notify child component about changes in Angular2

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

Suppose I have simple Angular2 component

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

        
2条回答
  •  无人及你
    2021-01-02 01:59

    You can put your additional logic or calculations into onChange method, that is called after all of component's bound properties are updated.

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

    Child {{ model }}

    `, }) class Child { model: number; onChange(map){ if(map.model) { console.log('doing crazy stuff here'); console.log(map.model); //SimpleChange {previousValue: 43, currentValue: 44} } } }

    Plunker

提交回复
热议问题