我有一个页面上有两个组件:
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-auto-loan-calculator中我有一个按钮:(click)="showKeypad()"
showKeypad()函数曾经有let k = this.app.getComponent('keypad');
这就是访问<ck-keypad>
组件
现在由于离子变为beta 7而角度变为RC,我收到以下错误: ORIGINAL EXCEPTION:TypeError:无法读取属性&#39; setControl&#39;未定义的
如何在Ck-auto-loan-calculator组件中访问键盘组件?
谢谢
答案 0 :(得分:1)
Ionic 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,示例带有用于说明的模态组件