@gsantamaria wrote:
Hi, I hope you're well!
I have a view for a timeline. Every post has a click=() to push to the owner user profile of that post. It load the profile and its content, when you back to timeline and click on another user post, the view doesnt reaload the provider, so the profile is the same visited first.
Here's the code:
feed.html:
<ion-card *ngFor="let post of feed;"> <ion-item> ... <h2 (click)="onViewProfiles(post.owner.id)">{{post.owner.first_name}} {{post.owner.last_name}}</h2> ... </ion-item> ... </ion-card>feed.ts:
export class FeedPage { ... onViewProfiles(user_id: string) { this.navCtrl.push(ProfilesPage); window.localStorage.setItem('user_id', user_id); }profile.ts:
export class ProfilesPage { ... public profile: any; constructor(public profilesService: ProfilesService, public navCtrl: NavController, public translate: TranslateService) { this.loadProfiles(); window.localStorage.removeItem('user_id'); } loadProfiles(){ this.profilesService.load() .then(data => { this.profile = data; }); }Finaly provider.ts:
@Injectable() export class ProfilesService { data: any; user_id: string; constructor(public http: Http) { this.user_id = window.localStorage.getItem('user_id'); } load() { if (this.data) { return Promise.resolve(this.data); } return new Promise(resolve => { this.http.get(global.API_PROFILES + this.user_id + '/') .map(res => res.json()) .subscribe(data => { this.data = data; resolve(this.data); this.user_id = null; }); }); } }remove Item, set user_id = null, none of these methods work, I think the problem is that the provider is not unloading and loading again. Is it something with the @injectable()?
Posts: 1
Participants: 1