2017-04-03 36 views
1

我正在使用离子2.我从检索到的图像位置从firebase和存储localstroage。离子图像src值为空

但我第一次加载我的应用程序的图片src值为null

<ion-header> 
    <ion-toolbar> 
     <ion-title *ngIf="currentuser === '7'" class="text-center"><img id="logo" src="./assets/images/logo_black.png" alt="Smart Permises"></ion-title> 
     <ion-title class="text-center"> 
     <h3>{{Apartmentname}}</h3> 
     <img id="logo" [src]="logo" alt="Smart Permises" imageViewer/> 
     </ion-title> 
    </ion-toolbar> 
    </ion-header> 

我检查localStorage的值。其fine.why图片src值为null。

this.logo=localStorage.getItem('Logo'); 
    console.log(this.logo); 
    this.Apartmentname=localStorage.getItem('Apartmentname'); 
    console.log(this.Apartmentname); 

再次我closedmy app.and打开。它工作正常。

为什么?

感谢

+0

你打电话给这个吗? 'this.logo = localStorage.getItem( '标志');'。生命周期事件? – Sampath

+0

Thanks.I在应用程序component.ts中调用构造函数 – ANISUNDAR

+0

是'app.html'文件中的图像吗? – Sampath

回答

0

<img id="logo" src={{logo}} alt="Smart Permises" imageViewer />

把它作为<img>已经src={{_varName}}完全为我工作至今。

注意:请确保您收到的URL确实有效。例如。尝试<img id="logo" src="<url>" alt="Smart Permises" imageViewer/>其中<url>实际上是一种资源。

+0

@ANISUNDAR:这工作? –