gpt4 book ai didi

angular - this.slides.length() 无法读取未定义的属性 'length'

转载 作者:太空狗 更新时间:2023-10-29 17:57:02 26 4
gpt4 key购买 nike

console.log(this.slides.length()); 打印 Cannot read property 'length' of undefined.setTimeout 为 100 时打印。

有什么方法可以判断子组件是否已经从父组件加载完毕?

<ion-content padding class="ttct-app-content">
<ion-slides>
<ion-slide>
<h1>Slide 1</h1>
</ion-slide>
<ion-slide>
<h1>Slide 2</h1>
</ion-slide>
<ion-slide>
<h1>Slide 3</h1>
</ion-slide>
</ion-slides>
</ion-content>
import { Component, ViewChild } from '@angular/core';
import { NavController, Slides } from 'ionic-angular';

@Component({
selector: 'page-compose',
templateUrl: 'compose.html',
})
export class Compose {
@ViewChild(Slides) slides: Slides;

constructor(public navCtrl: NavController) {
}

ngAfterViewInit(){
console.log(this.slides.length()); //Cannot read property 'length' of undefined
//works
/*
setTimeout(()=>{
console.log(this.slides.length());
},100);
*/

}

}

最佳答案

试试这个(你不需要导入任何其他东西):

ionViewDidEnter() {
console.log(this.slides.length());
}

还尝试使用 ngFor 加载 slider ,效果非常好

关于angular - this.slides.length() 无法读取未定义的属性 'length',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45488688/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com