我正在学习AngularJS,我已经用一个mvc应用程序来设置它。我正在尝试将以前在JQuery中编写的一小部分代码转换为AngularJS,但不知道如何使其工作。问题是我不知道如何用AngularJS在控制器中调用代码隐藏方法?
这就是它现在在JQuery中的工作方式:
//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);
}有人知道这是怎么做的吗?
发布于 2013-08-05 08:58:59
在角度上,它们的实现方式不同,而角有相同的模块。
下面是清单
http://docs.angularjs.org/api/ngResource.$resource
http://docs.angularjs.org/api/ng.$http
http://docs.angularjs.org/api/ng.$httpBackend
您需要从上面注入这个模块,通常使用下面的工厂方法编写服务如下:
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;
});
});https://stackoverflow.com/questions/18053552
复制相似问题