[英]why does the custom component run before the page is created in ionic 2?
I would like to implement a custom component in my ionic project and I followed this guide to realize it. 我想在我的离子项目中实现自定义组件,并按照本指南进行实现。
On my page, instantiate a variable to pass to my component 在我的页面上,实例化一个变量以传递给我的组件
export class NewSegmentPage {
name: any;
constructor(public navCtrl: NavController, public navParams: NavParams) {
this.name = "hello";
}
and in the template 并在模板中
...
<ion-content>
<slider [name]="name"></slider>
</ion-content>
Now I create my component 现在我创建我的组件
<ion-item>
<ion-range dualKnobs="true" pin="true" [(ngModel)]="structure"></ion-range>
</ion-item>
and retrieve the data that I pass to the variable by @Input 并通过@Input检索传递给变量的数据
@Input("coordinates") activity;
structure: any = { lower: 33, upper: 60 };
constructor() {
console.log(this.activity);
}
but this.activity variable is undefined. 但是this.activity变量是不确定的。
In addition, in the google console I saw that the component is created before the page and that's why it fails to pass the data. 另外,在Google控制台中,我看到该组件是在页面之前创建的,这就是为什么它无法传递数据的原因。 But, How does it behave like that?
但是,它的行为如何?
The execution is right but I was wrong to retrieve the this.activity variable in the constructor. 执行是正确的,但是在构造函数中检索this.activity变量是错误的。 Off of my constructor my variable is instantiated.
从我的构造函数中,我的变量被实例化。
ngAfterViewInit() {
console.log(this.activity);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.