AngularJS调用的WebMethod [英] AngularJS call webmethod

查看:155
本文介绍了AngularJS调用的WebMethod的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我学习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;
  });
});

这篇关于AngularJS调用的WebMethod的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆