I am trying to create a shared User data provider:
import {Injectable} from '@angular/core';
@Injectable()
export class User {
public name: string;
public email: string;
public password: string;
public birthday: string;
public settings: Settings;
public loggedIn: boolean;
constructor({
name = null, email = null, password = null, birthday = null,
settings = new Settings(),loggedIn = false
}: {
name?: string; email?: string; password?: string; birthday?: string;
settings?: Settings; loggedIn?: boolean;
} = {}) {
this.name = name;
this.email = email;
this.password = password;
this.birthday = birthday;
this.settings = settings;
this.loggedIn = loggedIn;
}
/**
* @returns {number} the user's age.
*/
get age(): number {
let age = Math.abs(Date.now() - new Date(this.birthday).getTime());
return Math.floor(age * 3.16887646E-11);
}
}
@Injectable()
export class Settings {
notificationSettings: NotificationSettings;
preferencesSettings: PreferencesSettings;
constructor({
notificationSettings = new NotificationSettings(),
preferencesSettings = new PreferencesSettings()
}: {
notificationSettings?: NotificationSettings;
preferencesSettings?: PreferencesSettings;
} = {}) {
this.notificationSettings = notificationSettings;
this.preferencesSettings = preferencesSettings;
}
}
@Injectable()
export class NotificationSettings {
// TODO
}
@Injectable()
export class PreferencesSettings {
// TODO
}
At the app component, I am declaring the provider, in order to make a user globally available.
When I am trying to build the project, I get a Can't resolve all parameters for User: (?)
error.
The problem occurs because of the settings in the User
constructor, but I am having a difficulty to find the error in my logic.