2017-12-06 19 views
0

子供から親コンポーネントに渡すデータがあります。空であるか、自動的に値があるかどうかをチェックします。@outputを使って子供から親コンポーネントにデータを送信

これは私のlogin.compunent.tsである - これが私のapp.compunentである親TS

emailData:string; 

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

- 子供はこれが私の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

私は、私は完全にあなたを理解していないが、あなたは自分の親にあなたの子供からのデータを渡す場合"自動的に"私は双方向バインド可能なプロパティを実装する必要があると信じています。

あなたはあなたの子供からsomethingを更新するたびに、この

child.ts

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

ようparent.html

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

は今、フィールドsomeFieldYouWantToTwoWayBindTo

に更新されますことをやります

今、あなたが何を確認したいのですか?年代somethingでのみsomeFieldYouWantToTwoWayBindTo

parent.ts

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

} 
+0

こんにちは用セッターを実装し、その後一定の場合をフィルタリングし、@SebOlensはご説明をお願いいたします。 – KUROYUKI