我正在尝试将 DI 与 Angular 一起使用,但是当我遇到错误时我被卡住了
Error: Unknown provider: dataServiceProvider <- dataService
这是我的 Main.js:
var app = {};
app.angularModule = angular.module('TestWeb', []);
app.angularModule.value("breeze", window.breeze);
app.angularModule.value("toastr", window.toastr);
这是我的记录器的一部分:
app.angularModule.factory('logger', function (toastr, $window) {
toastr.options.timeOut = 2000; // 2 second toast timeout
toastr.options.positionClass = 'toast-bottom-right';
var logger = {
error: error,
info: info,
success: success,
warning: warning,
log: log // straight to console; bypass toast
};
这是我的数据服务的一部分:
app.angularModule.factory = ('dataService', function (breeze, logger) {
breeze.config.initializeAdapterInstance("modelLibrary", "backingStore", true);
var mbservice = new breeze.DataService({
serviceName: "http://localhost:23758/api/",
hasServerMetadata: false,
});
var manager = new breeze.EntityManager({ dataService: mbservice });
manager.enableSaveQueuing(true);
var dataService = {
getAll: getAll,
createItem: createItem,
saveChanges: saveChanges,
};
这是我的示例控制器的一部分:
app.angularModule.controller('testCtrl', function($scope, breeze, dataService, logger) {
$scope.items = [];
$scope.getAll = function() {
dataService.getAll("tests")
.then(querySucceeded)
.fail(queryFailed);
};
$scope.getAll();
这是html的一部分:
这是完整的错误
Error: Unknown provider: dataServiceProvider <- dataService
at Error (<anonymous>)
at http://localhost:7122/Scripts/angular/angular.js:2734:15
at Object.getService [as get] (http://localhost:7122/Scripts/angular/angular.js:2862:39)
at http://localhost:7122/Scripts/angular/angular.js:2739:45
at getService (http://localhost:7122/Scripts/angular/angular.js:2862:39)
at invoke (http://localhost:7122/Scripts/angular/angular.js:2880:13)
at Object.instantiate (http://localhost:7122/Scripts/angular/angular.js:2914:23)
at http://localhost:7122/Scripts/angular/angular.js:4805:24
at http://localhost:7122/Scripts/angular/angular.js:4384:17
at forEach (http://localhost:7122/Scripts/angular/angular.js:137:20) angular.js:5754
(anonymous function) angular.js:5754
笔记:
我正在关注带有 DI 的微风示例 ToDO Angular:链接,并且我使用的 DI 与它们相同。但我得到错误,不知道为什么。