Error: Unknown provider: employeesProvider <- employees

后端 未结 2 515
没有蜡笔的小新
没有蜡笔的小新 2020-12-10 13:12

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

相关标签:
2条回答
  • 2020-12-10 13:17

    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">
    

    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">
    

    ... and presto, like nothing ever happened.

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

    0 讨论(0)
  • 2020-12-10 13:23

    Since you defined the factory called Employee, you should use the exact name to refer to this module when you inject it to the controller.

    var employeeCtrl = app.controller('EmployeeCtrl', [
          '$scope',
          'employees',
    

    Change to

    var employeeCtrl = app.controller('EmployeeCtrl', [
          '$scope',
          'Employee',
    
    0 讨论(0)
提交回复
热议问题