我正在构建一个Angular 4应用程序,我正在尝试使用如下所示的“模型”类:
export interface UserI {
uid?: string;
birthdate: number;
firstname: string;
}
export class User implements UserI {
uid: string;
birthdate: number;
firstname: string;
avatar: string;
numberOfPictures$: Observable<number>;
constructor(obj: any) {
if (!obj.uid)
throw new Error("User Class#constructor - No uid found for user.");
this.uid = obj.uid;
obj.firstname ? this.firstname = obj.firstname : this.firstname = '';
obj.birthdate ? this.birthdate = obj.birthdate : this.birthdate = 0;
obj.avatar ? this.avatar = obj.avatar : this.avatar = 'boy_1';
}
}
我想使用我的提供商之一来设置变量numberOfPictures$
我该怎么注射它?我习惯于看看注入组件的构造函数,但我不知道如何在这种特殊情况下继续。