【发布时间】:2015-03-20 12:24:28
【问题描述】:
在我正在构建的一个应用程序中,我想在 service(.factory(...)) 中使用 $cookie。
当我使用 $cookie 时,我得到 $injector/module 错误。有人可以在这方面帮助我吗?
这是我写的代码。
app.factory("AuthenticationService", function($location,$cookies,setUserCreds)
{
return {
login: function(credentials) {
if (credentials.username == "MyName" || credentials.password == "admin") {
$cookies.put("userName",credentials.username);
$location.path('/home');
}
}}});
【问题讨论】:
-
看起来你没有正确地进行依赖注入。查看答案。
标签: javascript angularjs cookies