Javascript 角度2相册创建
我想在Facebook上制作一张专辑 但是,当我将图片保存到firebase存储中,并返回我放入对象中的图片的URL时,仅当我添加新图片或移动光标时,视图不会刷新。当我从firebase获取URL时,如何自动刷新视图Javascript 角度2相册创建,javascript,angular,Javascript,Angular,我想在Facebook上制作一张专辑 但是,当我将图片保存到firebase存储中,并返回我放入对象中的图片的URL时,仅当我添加新图片或移动光标时,视图不会刷新。当我从firebase获取URL时,如何自动刷新视图 <div class="row pics"> <div class="col-md-4 col-xs-4"> <div class="newItem text-center">
<div class="row pics">
<div class="col-md-4 col-xs-4">
<div class="newItem text-center">
<a (change)="addPicture($event)" class="newAlbum"><input type="file" id="file"/>Add Picture</a>
</div>
</div>
<div class="col-md-4 col-xs-4" *ngFor="let item of newAlbum.pictures; let i = index">
<div class="Item">
<img src="{{item?.pictureS}}" alt="" >
</div>
<textarea class="picture-desc" placeholder="Say something about this photo..." (keyup)="onKey($event,i)">{{item.desc}}</textarea>
</div>
</div>
您可以使用
NgZone
在执行某些操作时触发更改检测。您需要将NgZone
注入组件。完成后,您可以使用,运行
来更新DOM
constructor( public zone: NgZone){}
that.zone.run(() =>
that.newAlbum.pictures.push(that.picItem);
});
您可以阅读更多关于ngZone
ps:我建议您使用新的箭头函数
来保存这个
,而不是使用那个
constructor( public zone: NgZone){}
that.zone.run(() =>
that.newAlbum.pictures.push(that.picItem);
});