$ injector:unpr未知提供商

时间:2015-06-26 03:43:29

标签: javascript angularjs controllers

我刚刚开始学习angularjs,并遇到了这个问题。运行应用程序时出现上述错误。 我的代码如下

app.js

'use strict';
angular.module('underscore', []).factory('_', function () {
return window._;
});

var myApp = angular.module('myApp', [
'ngRoute']);

myApp.config(function ($routeProvider) {
$routeProvider
    .when('/a',
    {
        controller: 'aController',
        templateUrl: 'module/a/a.html'
    })
    .otherwise({redirectTo: '/view1'});
});

a.js(控制器)

'use strict';

myApp.controller('aController',
function($scope,aCollection, $location) {
    $scope.foo= {

    };

    $scope.create= function() {
        aCollection.create($scope.foo);
        $location.path('/a-creation');
    };
});

aCollection.js(服务)

'use strict';

myApp.factory('aCollection', function($resource) {
return $resource('../api/dummy', {}, {
    create : {method: 'POST' }
})
});

错误是:

Error: [$injector:unpr] http://errors.angularjs.org/1.3.16/$injector/unpr?p0=%24resourceProvider%20%3C-%20%24resource%20%3C-%20aCollection
at Error (native)
at http://localhost:9080/lib/angular.min.js:6:417
at http://localhost:9080/lib/angular.min.js:38:7
at Object.d [as get] (http://localhost:9080/lib/angular.min.js:36:13)
at http://localhost:9080/lib/angular.min.js:38:81
at d (http://localhost:9080/lib/angular.min.js:36:13)
at Object.e [as invoke] (http://localhost:9080/lib/angular.min.js:36:283)
at Object.$get (http://localhost:9080/lib/angular.min.js:34:268)
at Object.e [as invoke] (http://localhost:9080/lib/angular.min.js:36:315)
at http://localhost:9080/lib/angular.min.js:38:110 <div data-ng-view="" class="ng-scope">

有人可以帮我解决这个问题吗?非常感谢!!!

1 个答案:

答案 0 :(得分:0)

你能尝试一下这个吗?

'use strict';

angular.module('myApp')
.controller('aController', ['$scope', 'aCollection', '$location', function($scope, aCollection, $location) {
    $scope.foo= {

    };

    $scope.create= function() {
        aCollection.create($scope.foo);
        $location.path('/a-creation');
    };
}]).factory('aCollection', function($resource) {
      return $resource('../api/dummy', {}, {
           create : {method: 'POST' }
      })
});

<强> EDITED

相关问题