[英]How do I inject ngCookies into a controller within an angularAMD define()?
我是AMD的新手。 這在AMD之前是這樣工作的:
angular.module('app')
.controller('RegisterCtrl', ['$scope', '$location', '$http', '$cookies', '$timeout', 'myConfig',
function($scope, $location, $http, $cookies, $timeout, myConfig) {
this.$cookies = $cookies;
this.$timeout = $timeout;
// Retrieving a cookie
$scope.cookielocation = $cookies.get('Location');
// Delete a cookie
$cookies.remove('Location', {path: '/'});
}]);
define(['angularAMD', 'angular-route', 'angular-cookies', 'banner', 'config', 'services', 'nullSP', 'timeAgo'], function (angularAMD) {
var app = angular.module("app", ['ngRoute', 'ngCookies']);
app.config(function ($routeProvider, $locationProvider) {
console.log("Enter route config");
$routeProvider
.when("/", angularAMD.route({
controller: 'HomeCtrl',
templateUrl: 'partials/welcome.html',
controllerUrl: 'controller_welcome'
}))
.when("/register", angularAMD.route({
controller: 'RegisterCtrl',
templateUrl: 'partials/register.html',
controllerUrl: 'controller_register'
}))
.when("/dashboard", angularAMD.route({
controller: 'DashboardCtrl',
templateUrl: 'partials/dashboard.html',
controllerUrl: 'controller_dashboard'
}))
.otherwise({
redirectTo: '/'
});
$locationProvider.html5Mode(true);
});
app.run(function ($browser) {
$browser.baseHref = function() { return window.location.pathname };
});
return angularAMD.bootstrap(app);
});
define(['app', 'angular-cookies'], function (app, cookies) {
app.controller('RegisterCtrl', ['$rootScope', '$scope', '$location', '$http', '$cookies', '$timeout', 'config',
function($rootScope, $scope, $location, $http, $cookies, $timeout, config) {
// Retrieving a cookie
$scope.cookielocation = $cookies.get('Location');
// Delete a cookie
$cookies.remove('Location', {path: '/'});
});
為什么會出現此錯誤:
錯誤:$ injector:unpr未知提供程序:$$ cookieReaderProvider <-$$ cookieReader <-$ cookies
以及如何解決?
固定:似乎這是angular.js和angular-cookies.js之間的版本差異
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.