gpt4 book ai didi

javascript - Angular 缺失法

转载 作者:行者123 更新时间:2023-12-02 17:54:59 24 4
gpt4 key购买 nike

我目前正在构建一个 Angular 应用程序,该应用程序具有公开服务的 C# 后端。我想使用 angularjs 资源来访问这些服务。当我在 Controller 中调用资源时,出现以下错误:

TypeError: Object function g(b){z(b||{},this)} has no method 'getCourse'
at new <anonymous> (http://127.0.0.1:81/ClientApp/controllers/CourseIndex.js:6:36)
at d (http://127.0.0.1:81/Scripts/angular/angular.min.js:30:352)
at Object.instantiate (http://127.0.0.1:81/Scripts/angular/angular.min.js:30:482)
at http://127.0.0.1:81/Scripts/angular/angular.min.js:59:495
at http://127.0.0.1:81/Scripts/angular/angular.min.js:47:450
at p (http://127.0.0.1:81/Scripts/angular/angular.min.js:7:367)
at U (http://127.0.0.1:81/Scripts/angular/angular.min.js:47:342)
at k (http://127.0.0.1:81/Scripts/angular/angular.min.js:42:309)
at k (http://127.0.0.1:81/Scripts/angular/angular.min.js:42:326)
at http://127.0.0.1:81/Scripts/angular/angular.min.js:41:371

这是我的 Controller :

coursewareApp.controller('CourseIndex', function ($scope, $location, Courses) {
$scope.courseOutline = Courses.getCourse(); //Error in this line
$scope.courseOutline.then(
function(course) {
$scope.courseOutline = fixFormat(course);
},
function(response) {
console.log(response);
});

这是我的服务:

coursewareApp.factory('Courses', function ($resource, $q) {
var resource = $resource('/api/Block', {},
{
getCourse: {
method: 'GET',
headers: { 'Authorization-Token': '6A594741380806DF128E28BDCC072859A1ECF0DC24478DDD890CC191C8357AFF12F837F657104E285BE8E2151F8631D148DEF89420024EDAA71DDB8404A1C1947ABD2BBE8002952DC891246CADCB1D452F445E773AB0CE8B4B9CF566A738ED7736AFC66B61FBFDCD59EDD68D2F8F4D5FF31DA0DD8F0CA98C10CA07F18C1C386462D0D2694385DA38C9F6C2A04B15B885AEBDF917E155014942040272E0F36B2D4E39303CBC430738902CF75093EAD11492AA87A9' },
url: '/api/Block/Courses',
}
});
return {
getCourse: function () {
var deferred = $q.defer();
resource.getCourse(
function(event) {
deferred.resolve(event);
},
function(response) {
deferred.reject(response);
});
return deferred.promise;
}
};
});

我已经阅读了许多类似问题的解决方案,但似乎没有一个适用于此。

提前致谢。

最佳答案

这似乎是一个缩小问题,尝试以缩小友好的方式声明 Controller \服务

coursewareApp.controller('CourseIndex', ['$scope', '$location', 'Courses',function ($scope, $location, Courses) {
}]);


coursewareApp.factory('Courses', ['$resource','$q',function ($resource, $q) {

}]);

关于javascript - Angular 缺失法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21033959/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com