这是我的代码,但我收到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:错误:未捕获(在承诺中):EXCEPTION:错误 ./TransactionPage类TransactionPage_Host - 内联模板:0:0 原始异常:TypeError:无法读取属性' infoForm'的 未定义
我缺少什么想法?
答案 0 :(得分:3)
删除'
@ViewChild(PersonalInfoPage)
如果查询类型,请使用该类型。如果查询模板变量,请使用字符串。
@ViewChild(PersonalInfoPage) personalInfo: PersonalInfoPage
@ViewChild(PaymentDetailsPage) paymentDetails: PaymentDetailsPage
@ViewChild(AddressPage) address: AddressPage
@ViewChild(IdentityPage) identityPage: IdentityPage