0
私はAngularJSでES6を使用しており、this guideの後にいます。サービスをクラスとして定義することを推奨します。私は$は、cookiestoreサービスを注入すると、このようなクラスに取り付けるてるサービス定義で
:
export default class Authentication {
constructor($cookieStore) {
this.$cookieStore = $cookieStore;
}
setAuthenticatedAccount(account) {
this.$cookieStore.put(JSON.stringify(account), 'authenticatedAccount');
}
isAuthenticated() {
return !!this.$cookieStore.get('authenticatedAccount');
}
}
私は、ユーザーがログインしているかどうかを反映するために、私のナビゲーションバーを更新したい、どの私は$watch
でやっている:
Cannot read property '$cookieStore' of undefined
:
これは、次のエラーが発生します。
どのようにサービスを登録しないで注入されていることを確認してください?あなたの例は、クラス定義のみを示しています。 – zeroflagL