无法通过 Angular2-RC4 中的 View Child 访问导入的组件
Can't access imported component via View Child in Angular2-RC4
这是我的代码,但是我收到 undefined
错误:
import {IONIC_DIRECTIVES} from 'ionic-angular'
@Component({
selector: 'personal-info',
templateUrl: 'build/pages/transaction/personal-info/personal-info.html',
directives: [IONIC_DIRECTIVES]
})
export class PersonalInfoPage {
infoForm: ControlGroup
constructor (
private formBuilder: FormBuilder,
) {
this.infoForm = formBuilder.group({//...})
})
}
import {PersonalInfoPage} from './personal-info/personal-info'
@Component({
templateUrl: 'build/pages/transaction/transaction.html',
directives: [PersonalInfoPage,PaymentDetailsPage,AddressPage,IdentityPage],
})
export class TransactionPage implements AfterViewInit {
@ViewChild('PersonalInfoPage') personalInfo: PersonalInfoPage
@ViewChild('PaymentDetailsPage') paymentDetails: PaymentDetailsPage
@ViewChild('AddressPage') address: AddressPage
@ViewChild('IdentityPage') identityPage: IdentityPage
constructor(
) {}
ngAfterViewInit () {
console.log(this.personalInfo.infoForm.valid);
}
浏览器错误:
EXCEPTION: Error: Uncaught (in promise): EXCEPTION: Error in
./TransactionPage class TransactionPage_Host - inline template:0:0
ORIGINAL EXCEPTION: TypeError: Cannot read property 'infoForm' of
undefined
知道我遗漏了什么吗?
删除 '
@ViewChild(PersonalInfoPage)
如果您查询类型,请使用该类型。如果您查询模板变量,请使用字符串。
@ViewChild(PersonalInfoPage) personalInfo: PersonalInfoPage
@ViewChild(PaymentDetailsPage) paymentDetails: PaymentDetailsPage
@ViewChild(AddressPage) address: AddressPage
@ViewChild(IdentityPage) identityPage: IdentityPage
这是我的代码,但是我收到 undefined
错误:
import {IONIC_DIRECTIVES} from 'ionic-angular'
@Component({
selector: 'personal-info',
templateUrl: 'build/pages/transaction/personal-info/personal-info.html',
directives: [IONIC_DIRECTIVES]
})
export class PersonalInfoPage {
infoForm: ControlGroup
constructor (
private formBuilder: FormBuilder,
) {
this.infoForm = formBuilder.group({//...})
})
}
import {PersonalInfoPage} from './personal-info/personal-info'
@Component({
templateUrl: 'build/pages/transaction/transaction.html',
directives: [PersonalInfoPage,PaymentDetailsPage,AddressPage,IdentityPage],
})
export class TransactionPage implements AfterViewInit {
@ViewChild('PersonalInfoPage') personalInfo: PersonalInfoPage
@ViewChild('PaymentDetailsPage') paymentDetails: PaymentDetailsPage
@ViewChild('AddressPage') address: AddressPage
@ViewChild('IdentityPage') identityPage: IdentityPage
constructor(
) {}
ngAfterViewInit () {
console.log(this.personalInfo.infoForm.valid);
}
浏览器错误:
EXCEPTION: Error: Uncaught (in promise): EXCEPTION: Error in ./TransactionPage class TransactionPage_Host - inline template:0:0 ORIGINAL EXCEPTION: TypeError: Cannot read property 'infoForm' of undefined
知道我遗漏了什么吗?
删除 '
@ViewChild(PersonalInfoPage)
如果您查询类型,请使用该类型。如果您查询模板变量,请使用字符串。
@ViewChild(PersonalInfoPage) personalInfo: PersonalInfoPage
@ViewChild(PaymentDetailsPage) paymentDetails: PaymentDetailsPage
@ViewChild(AddressPage) address: AddressPage
@ViewChild(IdentityPage) identityPage: IdentityPage