-1
我正在測試樣品CRUD使用Angular和微風下面的示例ToDo項目。 但由於某種原因,我得到錯誤無法調用未定義的方法'getAll'。 (我的OData託管於其他本地主機服務器上,而CORS啓用,我測試過它)角與微風錯誤無法調用方法的未定義
這裏是我的代碼:
Main.js:
var app = {};
app.adminMuscleGroup = angular.module('WebApp', []);
的DataService:
app.adminMuscleGroup.dataService = (function (breeze, logger) {
breeze.config.initializeAdapterInstances({ dataService: "OData" });
var servicename = 'http://localhost:23758/odata/';
var manager = new breeze.EntityManager(servicename);
manager.enableSaveQueuing(true);
var dataService = {
getAll: getAll,
};
return dataService;
function getAll() {
var query = breeze.EntityQuery.from("MuscleGroup").orderBy("Name");
return manager.executeQuery(query);
}
})(breeze, app.logger);
控制器:
app.adminMuscleGroup.controller('AdminMuscleGroupCtrl', function($scope) {
var dataService = window.app.dataService;
var logger = window.app.logger;
$scope.items = [];
$scope.getAllMuscleGroups = function() {
dataService.getAll()
.then(querySucceeded)
.fail(queryFailed);
};
$scope.getAllMuscleGroups();
function querySucceeded(data) {
$scope.items = [];
data.results.forEach(function (item) {
$scope.items.push(item);
});
$scope.apply();
logger.info("Fetched all Muscle Groups");
}
function queryFailed(error) {
logger.error(error.message, "Query failed");
}
}
這裏是整個錯誤:
ypeError: Cannot call method 'getAll' of undefined
at Object.$scope.getAllMuscleGroups (http://localhost:7122/Scripts/app/AdminMuscleGroup/MuscleGroupController.js:10:21)
at new <anonymous> (http://localhost:7122/Scripts/app/AdminMuscleGroup/MuscleGroupController.js:15:12)
at invoke (http://localhost:7122/Scripts/angular/angular.js:2902:28)
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)
at nodeLinkFn (http://localhost:7122/Scripts/angular/angular.js:4369:11)
at compositeLinkFn (http://localhost:7122/Scripts/angular/angular.js:4015:15)
at publicLinkFn (http://localhost:7122/Scripts/angular/angular.js:3920:30) angular.js:5754
(anonymous function)
現在我得到這個錯誤:'錯誤:未知的提供者:dataServiceProvider < - dataService' – hyperN