のすべてのパラメータ解決できません:アプリのコンポーネントでは私が共有ユーザーデータプロバイダを作成しようとしていますユーザー
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
}
を、私は、ユーザーがグローバルに利用できるようにするために、プロバイダを宣言しています。
プロジェクトをビルドしようとすると、Can't resolve all parameters for User: (?)
エラーが発生します。
この問題は、User
コンストラクタの設定のために発生しますが、私のロジックでエラーを見つけるのが難しいです。
チェックタイポので、たとえば、あなたは
app.module.ts
ファイルに追加することができますバレル ' – Aravind私はそれが注射可能であるとは思わない、またはそうすべきである。それは単なるデータクラスです。注入する場合は、InjectionTokenを使用します。 – jonrsharpe
@Aravindコンストラクタにはタイプミスがありません。また、私はバレルを使用していません。 – Manos