错误:未知提供商:employeesProvider< - 员工 [英] Error: Unknown provider: employeesProvider <- employees

查看:135
本文介绍了错误:未知提供商:employeesProvider< - 员工的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个时间试图弄清楚为什么我得到未知提供程序错误在角赫克。我检查了所有其他的问题,我能找到关于这个问题,最建议的依赖注入一个错误。然而,这并不在我看来,像我忘记注入什么。我一直试图让resolve属性喜欢的工作<一个href=\"http://stackoverflow.com/questions/11972026/delaying-angularjs-route-change-until-model-loaded-to-$p$pvent-flicker\">this通过后的MISKO。我能安慰注销员工资料它解决后,但后来我得到了未知的提供程序错误,其中prevents将数据从页面上被显示。

I am having a heck of a time trying to figure out why I'm getting the Unknown provider error in Angular. I've checked every other question I could find on the subject and most suggest an error in dependency injection. However, it doesn't seem to me like I'm forgetting to inject anything. I've been trying to get the resolve property to work like this post by Misko. I'm able to console log out the employee data after it's resolved, but then I get the Unknown provider error, which prevents the data from being shown on the page.

这里是我的路由器:

    "use strict";

    var app = angular.module('app',[
      'employeeServices'
    ]);

    app.config(appRouter);

    function appRouter ($routeProvider) {
      $routeProvider
        .when('/employees/:account_id', {
          controller: 'EmployeeCtrl',
          templateUrl: 'view/employee/view.html',
          resolve: employeeCtrl.resolve
        })

        .otherwise({ redirectTo: '/' });
    }

这里是我的控制器

    var employeeCtrl = app.controller('EmployeeCtrl', [
      '$scope',
      'employees',
      function ($scope, employees) {
        $scope.employee = employees;
        console.log($scope.employee);
      }
    ]);

    employeeCtrl.resolve = {
      employees: function (Employee, $q, $route) {
        var deferred = $q.defer();
        console.log("current params: ", $route.current.params.account_id);
        Employee.getOne({ id: $route.current.params.account_id }, function (successData) {
          deferred.resolve(successData);
        }, function (errorData) {
          deferred.reject(errorData);
        });
        return deferred.promise;
      }
    };

我的厂:

    angular.module('employeeServices', ['ngResource'])
      .factory('Employee', ['$resource', function ($resource) {
        return $resource('/employees/:id/json',
          {
            id: '@account_id'
          },
          {
            'save': {
              method: 'POST',
              isArray: false
            },
            'update': {
              method: 'PUT',
              params: {
                id: '@account_id'
              }
            },
            'remove': {
              method: 'DELETE',
              params: {
                id: '@account_id'
              }
            },
            'getOne': {
              method: 'GET',
              params: {
                id: '@account_id'
              },
              isArray: false
            },
            'query': {
              method: 'GET',
              params: {
                id: '@account_id'
              },
              isArray: true
            }
          }
        );
      }]);

任何建议将是如此之大的AP preciated!

Any suggestions would be so greatly appreciated!

推荐答案

所以,问题是,我是建立通过NG-控制器EmployeeCtrl控制器部分我的观点里,像这样:

So the problem was that I was setting up the EmployeeCtrl controller through ng-controller inside my partial's view, like so:

    <div class="viewPage" ng-controller="EmployeeCtrl">

在使用决心,但是,建立控制器必须通过路由器,以便它可在运行时进行。我删除了 NG-控制器=EmployeeCtrl ...

When using resolve, however, the controller set up must be done through the router in order for it to be available at runtime. I removed the ng-controller="EmployeeCtrl...

    <div class="viewPage">

...和preSTO,像什么发生过。

... and presto, like nothing ever happened.

我要指出,我获得了帮助从善良,耐心乡亲在的AngularJS IRC频道 ..

I have to note that I received help from the kind, patient folks over on the AngularJS IRC channel...

这篇关于错误:未知提供商:employeesProvider&LT; - 员工的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆