Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

I am trying to fetch records via ajax and displaying using AngularJS. But my code even not invoking controller action.

I am trying this code..

<div ng-controller="MyCtrl">
<div ng-repeat="result in products">
    {{result.ProductName}}
</div>
</div>

Ajax :

function MyCtrl($scope) {
  $.ajax({
    url: "/Products/Get/",
    type: "POST",
    success: function (data) {
      // Success message
      var myApp = angular.module('myApp', []);
      $scope.products = data;
    },
    error: function () {
      // Fail message
    },
  });
}

I am using this post to make it work.

share|improve this question
    
You don't have controller MyCtrl – HappyCoding Jul 24 at 11:01

Your approach is wrong. You should use angularJS's controller directive to invoke services to consume json data.

<script type="text/javascript">
    var app = angular.module('myApp', []); 
    app.controller('MyCtrl', function ($scope, $http) {  
        $http.get('/Products/Get/').success(function (data) {  
            $scope.products = data;
        });
    });
</script>

I had written an article few days ago on the same. You can go through here. This might be helpful.

share|improve this answer
    
Since success is deprecated you should use then instead of success. – developer033 Jul 24 at 19:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.