2017-12-06 2 views
0

자녀가 부모 구성 요소로 전달하는 일부 데이터가 있으며 비어 있는지 또는 자동으로 값이 있는지 확인하고 싶습니다.@output을 사용하여 자식에서 부모 구성 요소로 데이터를 전송합니다.

이 내 login.compunent.ts에 -

emailData:string; 

    onUpdate(userEmail:string){ 
    console.log("userEmail") 
    if(userEmail !== ''){ 
     this.emailData = userEmail 
     console.log(userEmail) 
    } 
    } 

이 내 app.compunent에 TS 부모 - 아이는 내 app.compunent.ts이이

@Output() update=new EventEmitter<string>(); 
userEmail = "[email protected]"; 
authUser(loginForm) {  
     this.update.emit(userEmail); 
     this.router.navigate(['/home']); 
    } 

의 TS. html - parernt html

{{emailData}} 
<router-outlet (update)="onUpdate($event)"></router-outlet> 

답변

0

나는 완전히 이해하고 있지만 자녀의 데이터를 부모에게 전달하려는 경우 확실하지 않습니다. "자동"나는 양방향 바인딩 가능한 속성을 구현해야한다고 생각합니다.

당신은 어떻게 그 같은

child.ts

export class SomeComponent { 
    ... 
    @Input() something; 
    // it's important to name it with the 'Change' suffix 
    @Output() somethingChange = new EventEmitter(); 
    ... 

parent.html 당신이 필드 someFieldYouWantToTwoWayBindTo

를 업데이트됩니다 자녀의 something을 업데이트 할 때마다 지금

<some-component [(something)] = "someFieldYouWantToTwoWayBindTo"></some-component> 

이제 무엇을 확인 하시겠습니까? 의를 something에 만 다음 someFieldYouWantToTwoWayBindTo

parent.ts

_someFieldYouWantToTwoWayBindTo 
set someFieldYouWantToTwoWayBindTo(value) { 
    if(value !== '') 
     this._someFieldYouWantToTwoWayBindTo = value; 

} 
+0

안녕에 대한 세터를 구현 어떤 경우 필터는 @SebOlens는 설명 주셔서 감사합니다. – KUROYUKI

관련 문제