首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将ngCookies注入到angularAMD定义()中的控制器中?

如何将ngCookies注入到angularAMD定义()中的控制器中?
EN

Stack Overflow用户
提问于 2015-12-02 03:55:05
回答 1查看 473关注 0票数 1

我是AMD的新手。这在AMD之前是这样的:

代码语言:javascript
复制
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: '/'});             
 }]);

关于AMD,我把它放在一起: app.js:

代码语言:javascript
复制
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);
  });

我的controller_register.js:

代码语言:javascript
复制
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

我该怎么解决呢?

EN

回答 1

Stack Overflow用户

发布于 2015-12-02 23:35:34

修正:它似乎是angular.js和角烹饪的版本上的区别。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34034639

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档