Monday, 20 February 2017

AngularJS Calling webservices or Webmethod

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>

<div  ng-app="myApp" >
        <div ng-controller="myCtrl">
   <table>
       <tr ng-repeat="x in showData">
           <td>{{x.ProcessName}}</td>
           <td>{{x.ProjectName}}</td>
       </tr>
   </table>

        </div>
    </div>


<script>
var app = angular.module("myApp", []);
app.controller('myCtrl', function ($scope, $http)
{
    var webAbsoluteURL = _spPageContextInfo.webAbsoluteUrl;
    var methodURL = webAbsoluteURL + "/_layouts/15/MainDashBoad/WebMethod.aspx/BindTasks";
    var param = {};
    param.localCulturalId ="1033";
    param.taskBox = "Inbox";
    param.days = "All";
    param.WebURL = webAbsoluteURL;
    $http({
        method: "POST",
        url: methodURL,
        dataType: 'json',
        data:param,
        headers: {
            "Content-Type": "application/json"
        }
    }).success(function (data, status)
    {
        $scope.showData = JSON.parse(data.d);//data.d;
     //   console.log(JSON.parse(data.d));
    })
    .error(function (data, status)
    {
        $scope.status = status;
        console.log(status);
    });
});
</script>

No comments:

Post a Comment