0

I am build an Angular 4 app in which I am trying to use "model" classes like the following:

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';
  }

}

I would like to use one of my provider to set the variable numberOfPictures$

How can I inject it? I am used to see Injection the constructor of components but I don't know how to proceed in this particular case.

2
  • Possible duplicate of How to inject Service into class(not component) Commented Dec 18, 2017 at 14:48
  • maybe create a function in your provider than return a new User (and init by this method) ? So when needed a new User, construct it throw your provider, not directly. Commented Dec 18, 2017 at 14:52

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.