RAPRequestService.js
angular.module('RecruitmentAuthorisationProcessApp').factory('RAPRequestsService ', function ($http) {
console.log('RAPRequestsService.js loaded...')
var RAPRequestsService = {};
RAPRequestsService.getRAPRequests = function () {
return $http.get('/RAPRequests/GetRAPRequestsJSON');
};
return RAPRequestsService;
});
RAPRequestsController.js
angular.module('RecruitmentAuthorisationProcessApp').controller('RAPRequestsCont roller', ['$scope','RAPRequestService',function ($scope, RAPRequestService) {
$scope.getRAPRequests = function () {
RAPRequestsService.getRAPRequests().success(function (rapRequests) {
$scope.data = rapRequests;
console.log($scope.data);
}).error(function (error) {
$scope.status = 'Unable to load rap requests: ' + error.message;
console.log($scope.status);
});
}
}]);
RecruitmentAuthorisationProcessApp.js
var RecruitmentAuthorisationProcessApp = angular.module('RecruitmentAuthorisationProcessApp', ['ngRoute']);
RecruitmentAuthorisationProcessApp.factory('RAPRequestsService', RAPRequestsService);
当我加载视图并打开开发人员工具时,我看到错误:
未捕获错误:[$ injector:nomod] http://errors.angularjs.org/1.6.5/ $ injector / nomod?p0 = RecruitmentAuthorisationProcessApp 角度:1 角度:1 在t(角度:1) at Object.module(angular:1) 在RecruitmentAuthorisationProcessApp:1
我的实施缺失了什么?
我的脚本在Bundle.Config中注册并加载到_Layout.cshtml。
答案 0 :(得分:0)
所以问题在于我如何尝试在BundleConfig.cs中注册该服务 我试着做一个.IncludeDirectory和angular并不是那样的。相反,我必须使用.Include(..指定文件路径)单独包含服务。 我不知道为什么它会拒绝.IncludeDirectory,它看起来更干净,但会在时间允许的情况下重新审视。 对于有类似问题的任何人,请参阅此文章:https://blog.mariusschulz.com/2015/02/22/bundling-and-minifying-an-angularjs-application-with-asp-net-mvc