AngularJS调用的WebMethodAngularJS、WebMethod

由网友(撩妹大师)分享简介:我学习AngularJS,我已经用MVC应用程序设置。我想一小块code那是在之前的JQuery写入AngularJS但无法弄清楚如何得到它的工作转换。问题是,我不知道该怎么称呼我的控制器codebehind法AngularJS?I'm learning AngularJS and I've set it up wi...

我学习AngularJS,我已经用MVC应用程序设置。我想一小块code那是在之前的JQuery写入AngularJS但无法弄清楚如何得到它的工作转换。问题是,我不知道该怎么称呼我的控制器codebehind法AngularJS?

I'm learning AngularJS and I've set it up with an mvc application. I'm trying to convert a small piece of code that was written before in JQuery to AngularJS but can't figure out how to get it working. The problem is that I don't know how to call a codebehind method in my controller with AngularJS ?

这是它是如何在现在的JQuery工作:

This is how it is working now in 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);
 }

任何人的想法如何做到这一点?

Anyone an idea how this is done ?

推荐答案

在他们的角度是不同的实现方式和角度对同一模块

In angular their are different way to achieve this and angular has module for the same

下面是列表

http://docs.angularjs.org/api/ngResource 。$资源

http://docs.angularjs.org/api/ng 。$ HTTP

http://docs.angularjs.org/api/ng 。$ httpBackend

http://docs.angularjs.org/api/ng.$httpBackend

您需要从上述注入这个模块,一般人写的服务低于这个工厂使用是mehthod的例子:

You need to inject this module from above, generally people write service for this using factory mehthod below is the example:

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;
  });
});
阅读全文

相关推荐

最新文章