2017-05-12 1 views
0

내가 업데이트 된 값을 감지하지 못하는 템플릿 내가 MyComponent을 테스트하고 comp.ngOnInit()을 수행 할 때 SubComponent트리거 변경 감지

를 MyComponent이

@Component({ 
    selector: 'my-component', 
    template: ` 
    <sub-component [input]="property"></sub-component> 
    ` 
}) 

export class MyComponent implements OnInit { 
    property: string; 
    constructor() { } 

    ngOnInit() { 
    this.property = 'value passed to sub component'; 
    } 
} 

과 같은 포함입니다 MyComponent, SubComponent을 테스트입니다 가정 해 보겠습니다 input입니다.

어떻게 SubComponent에서 변경 사항을 감지 할 수 있습니까?

+0

이렇게해도 작동합니까? 나는'@ Input' 주석을 보지 못했고, 여러분의 자녀에게 잘못된 속성 이름 ('property')을 사용하고 있습니다. – Alex

답변

0

subComponent에서 lifeCycle hook OnChanges을 사용할 수 있습니다.