Jquery AngularJS调用webmethod
我正在学习AngularJS,并用mvc应用程序进行了设置。 我正在尝试将以前在JQuery中编写的一小段代码转换为AngularJS,但不知道如何让它工作。问题是我不知道如何使用AngularJS在控制器中调用codebehind方法 这就是它现在在JQuery中的工作方式:Jquery AngularJS调用webmethod,jquery,asp.net-mvc,angularjs,Jquery,Asp.net Mvc,Angularjs,我正在学习AngularJS,并用mvc应用程序进行了设置。 我正在尝试将以前在JQuery中编写的一小段代码转换为AngularJS,但不知道如何让它工作。问题是我不知道如何使用AngularJS在控制器中调用codebehind方法 这就是它现在在JQuery中的工作方式: //JQuery calling code behind $(document).on("click", ".open-AppDescriptionDialog", function () { var title
//JQuery calling code behind
$(document).on("click", ".open-AppDescriptionDialog", function () {
var title = "Title";
var state = "active";
//call method
$.post('<%= Url.Action("StatusInfoString") %>', { header: title, status: state }, ParseResult);
});
//method in controller
[HttpPost]
public ActionResult StatusInfoString(string path, string status)
{
ServiceClient serviceClient = new ServiceClient();
var data = serviceClient.GetResults();
return Content(data);
}
//JQuery调用代码隐藏
$(文档)。在(“单击“,”上。打开AppDescriptionDialog”,函数(){
var title=“title”;
var state=“活动”;
//调用方法
$.post(“”,{header:title,status:state},ParseResult);
});
//控制器中的方法
[HttpPost]
public ActionResult StatusInfoString(字符串路径、字符串状态)
{
ServiceClient ServiceClient=新ServiceClient();
var data=serviceClient.GetResults();
返回内容(数据);
}
有人知道如何做到这一点吗?在angular中,他们实现这一点的方式不同,angular拥有相同的模块 下面是清单 .$资源 .$http .$httpBackend 您需要从上面注入此模块,通常人们使用factory方法为此编写服务,下面是示例:
app.factory('myService', function($http) {
return {
getList:function(params){
var promise= $http({url: 'ServerURL',method: "POST", params: params}).then(function(response,status){
return response.data;
});
// Return the promise to the controller
return promise;
}
}
});
app.controller('MainCtrl', function($scope, myService) {
myService.getList(function(data) {
$scope.foo = data;
});
});
看看AngularJS中的
$http
服务,很抱歉,我是AngularJS的新手。我将如何去真正实现这一点?你能链接到一些小例子吗?嗨,我得到的是“myService未定义”。如何创建“myService”?请检查工作示例@