gpt4 book ai didi

angularjs - Angular ngCookies

转载 作者:行者123 更新时间:2023-12-02 22:55:41 26 4
gpt4 key购买 nike

我无法将 ngCookies Angular 模块注入(inject)我的项目中。你能告诉我为什么吗?我已完成文档中的所有说明。如果可能的话请编写真实的代码。

var mainApp =  angular.module('mainApp',["ngCookies","ngRoute"]).config(appConfig);

appConfig.$inject=['$routeProvider','$cookieStore','$cookies'];

function appConfig ($routeProvider){

$routeProvider
.when(
'/add',
{
templateUrl:"view/add/index.html"
}
)
.when(
'/login',{
templateUrl:'view/login/index.html',
controller:'loginController'
}
)
.otherwise({
redirectTo:'/'
})
};
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="assets/js/jquery/dist/jquery.js" charset="utf-8"></script>
<script src="assets/js/angular/angular.js" charset="utf-8"></script>
<script src="assets/js/angular-cookie/angular-cookie.js"></script>
<script src="assets/js/angular-route/angular-route.js" charset="utf-8"></script>
<script src="assets/js/angular-resource/angular-resource.js" charset="utf-8"></script>
<script src="assets/js/app/main.js" charset="utf-8"></script>
<script src="assets/js/app/controllers/loginController.js"></script>
<script src="assets/js/app/services/userLogin.js"></script>
</head>
<body>
<div ng-app = "mainApp" class="main">
<a id="add" href="#add">Дальше</a>
<a href="#">Назад</a>
<a href="#login">Логин</a>
<div ng-view>

</div>
</div>
</body>
</html>

错误如下:

angular.js:68 未捕获错误:[$injector:modulerr] 无法实例化模块 mainApp,原因是:错误:[$injector:modulerr] 无法实例化模块 ngCookies,原因是:错误:[$injector:nomod] 模块“ngCookies”不可用!您要么拼错了模块名称,要么忘记加载它。如果注册模块,请确保将依赖项指定为第二个参数。 http://errors.angularjs.org/1.4.4/ $injector/nomod?p0=ngCookies

最佳答案

如果您通过在 angular-cookie 末尾和“.js”之前添加一个“s”字母来更改脚本源,会有帮助吗,如下所示:

<script src="assets/js/angular-cookie/angular-cookies.js"></script>

基于angular-ngcookies API ,它的用法如下:

<script src="angular-cookies.js">

关于angularjs - Angular ngCookies,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32187016/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com