I recently started using TypeScript and encountered this error:
Type '{}' is not assignable to type 'Profile'.
within the context of this.profile. Can anyone suggest a solution?
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { AngularFireAuth } from 'angularfire2/auth';
import { AngularFirestore } from 'angularfire2/firestore';
import { Profile } from './../../models/profile';
@IonicPage()
@Component({
selector: 'page-profile',
templateUrl: 'profile.html',
})
export class ProfilePage {
profile = {} as Profile;
constructor(private afs: AngularFirestore, private afAuth: AngularFireAuth,
public navCtrl: NavController, public navParams: NavParams) {
}
ionViewWillLoad() {
this.afAuth.authState.take(1).subscribe(data => {
let profileCollection = this.afs.collection('profiles').doc(`${data.uid}`).valueChanges();
profileCollection.subscribe(profile => this.profile = profile);
})
}
}