AngularJS$http.get调用MVC5操作
AngularJS $http.get to call a MVC5 action
我是AngularJS的新手。我已经用AngularJS创建了一个应用程序。我有一个应用程序文件夹,里面有一个用于文件的列表文件夹:List.html和
listcontroller.js
angSalaryApp.controller('listController',
function ListController($scope, ListService) {
$scope.list = listService.newlist;
$scope.count = 0;
$scope.submitForm() = function () {
};
$scope.updateName() = function () {
$scope.count++;
};
});
listService.js
angSalaryApp.factory('ListService',
["$http",
function ($http) {
var newList = function(){
return $http.get("Areas/Employer/List/newlist");
};
}
]);
listdirective.js
angSalaryApp.directive("listForm", function () {
return {
restrict: "E",
templateUrl: "app/list/list.html"
}
});
在应用程序文件夹中,我有一个JS文件,名为SalaryApp.JS
var angSalaryApp = angular.module('angSalaryApp',[])
当我的代码调用$http.get时,我得到了一条错误消息
Error: [$injector:undef] Provider 'ListService' must return a value from $get factory method.
http://errors.angularjs.org/1.4.6/$injector/undef?p0=ListService
at enforcedReturnValue (http://localhost:5137/Scripts/angular.js:4330:9)
at invoke (http://localhost:5137/Scripts/angular.js:4476:7)
at Anonymous function (http://localhost:5137/Scripts/angular.js:4293:13)
at getService (http://localhost:5137/Scripts/angular.js:4435:11)
at invoke (http://localhost:5137/Scripts/angular.js:4464:9)
at Anonymous function (http://localhost:5137/Scripts/angular.js:9127:11)
at nodeLinkFn (http://localhost:5137/Scripts/angular.js:8239:13)
at compositeLinkFn (http://localhost:5137/Scripts/angular.js:7671:13)
at compositeLinkFn (http://localhost:5137/Scripts/angular.js:7675:13)
at publicLinkFn (http://localhost:5137/Scripts/angular.js:7546:30)
在控制器中注入ListService
,因此调用ListService.newlist
而不是listService.newlist
angSalaryApp.controller('listController',
function ListController($scope, ListService) {
$scope.list = ListService.newlist;
});
在工厂中,它应该返回object
,但您没有返回任何object
,所以通过在返回对象中添加函数来返回对象。
angSalaryApp.factory('ListService', ["$http",
function($http) {
return {
newList: newList
};
function newList() {
return $http.get("Areas/Employer/List/newlist");
}
}
]);
相关文章:
- 如何使jQuery插件函数可调用以供独立使用,而不在集合上操作
- Jquery菜单操作不稳定,定位不正确,存在一般错误
- 如何确定javascript已经完成了某些操作.ios上的
- 防止Alt+Shift默认操作或检测多种操作系统语言的Javascript
- 从JavaScript访问struts操作中的属性
- fluxxor向一个flux实例添加一组以上的操作
- Jquery表单验证插件-如果选中复选框,如何在提交时执行某些操作
- 操作放置在画布上的元素之间的连接
- 使用“+="操作人员
- Rails操作只调用一次,但我在ajax中每秒钟都调用一次
- Jquery未定义函数正在停止其他操作
- 如何操作iframe之外的元素
- javascript对象操作:根据指定条件选择属性
- jQuery:暂停按钮可以暂停所有其他操作
- 用于选择/文本框操作的JavaScript
- Google 脚本:用于创建日历活动的脚本运行时不会出错,但不会执行任何操作
- 通过javascript操作图像,非常简单
- 如何在MVC5中ajax调用的部分视图中引用外部javascript
- 如何将复选框的值传递给 MVC5 中的操作结果
- AngularJS$http.get调用MVC5操作