2016-11-15 11 views
1

Inputとマークされた変数を動的に更新するこのアプリケーションがあります。私のTSにIonic 2 - 更新元の値の変更時の入力値

が、私はこのようなものを持っている:

@Component({ 
    selector: 'page2', 
    templateUrl: 'page2.html', 
    inputs: ['currentTitle'] 
}) 
export class Page2 { 
    currentTitle: string; 

    constructor() { 
    console.log(currentTitle); 
    } 
} 

と親ページの私のHTMLで

<page1 [example]="post.title"></page1> 

私は、currentUsernameはコンストラクタでロードされないことを知っているが、デモ目的のためだけに。

私が望むのは、post.titleが変更された場合、currentTitleはリロードするなどしなくても変更されます。

どうすればこの問題を解決できますか?

答えて

2

あなたのts次のように見えるためにあなたの変数を変更する必要がありますで、そのままあなたのHTMLを残すことができます:

@Input set currentTitle(value: string) { 
    if(value != undefined){ 
     this._currentTitle = value; 
    } 
} 

_currentTitle: string 

今すぐあなたの_currentTitleの代わりcurrentTitleを使用(または_currentTitleとスワップにHTMLを変更できますか変数)。

関連する問題