2016-05-31 73 views
1

我有兩個組件的網頁上:角2次訪問組件

Page({ 
    template: '<ion-navbar *navbar class="contact_navbar"> 
        <ion-title>Loan Calculator</ion-title> 
       </ion-navbar> 
       <ion-content><ck-auto-loan-calculator type="normal"></ck-auto-loan-calculator></ion-content><ck-keypad id="keypad"></ck-keypad>', 
    directives: [[ckAutoLoanCalculator], [Keypad]] 
}) 
export class LoanCalculator {} 

現在CK-汽車貸款計算器裏我有了一個按鈕:(click)="showKeypad()"

的showKeypad使用()函數具有let k = this.app.getComponent('keypad');並且這訪問<ck-keypad>部件

現在,因爲離子改變爲7的β和角度改變爲RC時,得到下面的錯誤: 原始異常:TypeEr ror:無法讀取未定義的屬性'setControl'

如何在Ck-auto-loan-calculator組件中訪問鍵盤組件?

謝謝

回答

1

離子2 getComponent已被棄用,可以傳遞該組件作爲輸入提供給另一個部件。

您可以從模板使用此語法傳遞:

<ck-auto-loan-calculator type="normal" [keypad]="keypad"></ck-auto-loan-calculator> 
<ck-keypad #keypad></ck-keypad> 

ckAutoLoanCalculator

@Input() keypad: Keypad 

然後隨時隨地在你ckAutoLoanCalculator

this.keypad.open() // assumes there's a public method on keypad component called open 

Plunker for passing components as inputs,做的例子有用於說明的模態組件