【问题标题】:AngularJS injection error in a resolve解决中的 AngularJS 注入错误
【发布时间】:2018-03-05 11:02:06
【问题描述】:

我正在尝试将用户配置文件元数据作为一个 promise 放入一个解析中,然后另一个 promise 使用它来根据用户配置文件中的值获取信息。

myApp.config( function myAppConfig ( $routeProvider, authProvider, $httpProvider, $locationProvider, jwtInterceptorProvider) {

    $routeProvider.when('/wapmap', {
        templateUrl:  'wap_tools/wap_map.html',
        controller: 'wapMapClr',
        resolve: {
            mapres: function(profilePromise, service2) {
                profilePromise.then(function(profile) {
                    var viewerId = profile.app_metadata.viewers[1].viewerId;
                     return service2.getPromise(viewerId)
                })
                     .then(function(response2) {    
                       makelayerGroup(response2);
                       mapView(response2);
                       hasPhotos = response2.vwrSettings[0].photos;
                       return
                  })
            })
          }
        },
        requiresLogin: true
    });

这是 authProvider。它也包含在配置中。

          authProvider.init({
          domain: 'someapp.eu.auth0.com',
          clientID: 'abcdsefghqwert12345',
          callbackURL: location.href,
          //URL when not logged in 
          loginUrl: '/Login' 

          });


      authProvider.on('loginSuccess', function($rootScope, $location, profilePromise, idToken, store, auth, userService) {
      console.log("Login Success");
      profilePromise.then(function(profile) {

          userService.setUser(auth.profile); 

          store.set('profile', profile);
          store.set('token', idToken);
          $location.path('/wapmap');
      });
      $rootScope.loggedIn = auth.isAuthenticated;
      $location.path('/wapmap');
      });

这会引发以下错误:

     [$injector:unpr] Unknown provider: profilePromiseProvider <- profilePromise <- mapres
  http://errors.angularjs.org/1.5.8/$injector/unpr?p0=profilePromiseProvider%20%3C-%20profilePromise%20%3C-%20mapres
            at angular.js:68
            at angular.js:4511
            at Object.getService [as get] (angular.js:4664)
            at angular.js:4516
            at getService (angular.js:4664)
            at injectionArgs (angular.js:4688)
            at Object.invoke (angular.js:4710)
            at angular-route.min.js:10
            at Object.forEach (angular.js:335)
            at angular-route.min.js:10

所以这看起来像是一个注入错误 - 我如何将 profilePromise 数据放入解析中?

【问题讨论】:

  • 在开发过程中不要使用缩小版的 angular.js。
  • 尝试将profilePromise注入应用配置:.config(['$routeProvider', 'profilePromise', function($routeProvider, profilePromise){$routeProvider.when...
  • 确保注入 profilePromise 服务
  • @Sibi Raj 谢谢。我已更改为 angular.js 的非缩小版本,并使用非缩小错误消息更新了问题。
  • 感谢您的回复。我已经在问题中添加了承诺的设置位置(在“authProvider”中)。它也在 myApp.config 中定义。

标签: javascript angularjs auth0


【解决方案1】:

error 告诉你:

未知提供者:profilePromiseProvider

确保您正确定义了profilePromise service/factory 并已加载

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-06
    • 2016-09-16
    • 2011-04-20
    • 1970-01-01
    相关资源
    最近更新 更多