我的个人资料图片仅在我在应用加载时触摸它后才会出现
My profile pic only appears after I touch it on app load
我用 Ionic 4、Firebase、Angular 创建了一个社交媒体应用程序,它在 Android 上运行良好。但是在 iOS 上,当我加载应用程序时,除非我实际触摸它,否则我的个人资料照片不会出现。
这是代码
async ngOnInit() {
firebase.auth().onAuthStateChanged(user => {
console.log('onAuthStateChanged', user.uid);
this.currentUser = user;
this.imageService.getImageDownloadUrl( 'profilePicture', user.uid)
.then((photo) => {
console.log('getImageDownloadUrl', photo);
this.profilePicture = (photo === 'undefined') ? 'false' : photo;
console.log('profilePicture', this.profilePicture);
});
});
}
<div class="profilePhoto" [ngSwitch]="profilePicture">
<div *ngSwitchDefault>
<img [src]="profilePicture" (click)="Present('profilePicture')">
</div>
<div class="logo" *ngSwitchCase="'false'">
<ion-img style="padding-top: 25px; " src="assets/image/SpaghettiPlus2.png" (click)="openImagePicker('profilePicture')"></ion-img>
</div>
</div>
我不需要用 Android 触摸图片,它只是在加载时出现,但是用 iOS,它不会加载实际的图片,它只会保持默认图片直到我真正触摸图片然后它神奇地出现了。
试试 NgZone,因为我使用下面的代码,你会得到你想要的吗
constructor(ngZone: NgZone){ }
async ngOnInit() {
firebase.auth().onAuthStateChanged(user => {
this.currentUser = user;
this.imageService.getImageDownloadUrl('profilePicture', user.uid)
.then((photo) => {
console.log('getImageDownloadUrl', photo);
this.ngZone.run(() => {
this.profilePicture = (photo === 'undefined') ? 'false' : photo;
console.log('profilePicture', this.profilePicture);
}
});
});
}
我用 Ionic 4、Firebase、Angular 创建了一个社交媒体应用程序,它在 Android 上运行良好。但是在 iOS 上,当我加载应用程序时,除非我实际触摸它,否则我的个人资料照片不会出现。
这是代码
async ngOnInit() {
firebase.auth().onAuthStateChanged(user => {
console.log('onAuthStateChanged', user.uid);
this.currentUser = user;
this.imageService.getImageDownloadUrl( 'profilePicture', user.uid)
.then((photo) => {
console.log('getImageDownloadUrl', photo);
this.profilePicture = (photo === 'undefined') ? 'false' : photo;
console.log('profilePicture', this.profilePicture);
});
});
}
<div class="profilePhoto" [ngSwitch]="profilePicture">
<div *ngSwitchDefault>
<img [src]="profilePicture" (click)="Present('profilePicture')">
</div>
<div class="logo" *ngSwitchCase="'false'">
<ion-img style="padding-top: 25px; " src="assets/image/SpaghettiPlus2.png" (click)="openImagePicker('profilePicture')"></ion-img>
</div>
</div>
我不需要用 Android 触摸图片,它只是在加载时出现,但是用 iOS,它不会加载实际的图片,它只会保持默认图片直到我真正触摸图片然后它神奇地出现了。
试试 NgZone,因为我使用下面的代码,你会得到你想要的吗
constructor(ngZone: NgZone){ }
async ngOnInit() {
firebase.auth().onAuthStateChanged(user => {
this.currentUser = user;
this.imageService.getImageDownloadUrl('profilePicture', user.uid)
.then((photo) => {
console.log('getImageDownloadUrl', photo);
this.ngZone.run(() => {
this.profilePicture = (photo === 'undefined') ? 'false' : photo;
console.log('profilePicture', this.profilePicture);
}
});
});
}