0

I have retrieved itemcount of a list using http service, but how do I display the count on the UI?

PFB the code:

var spApp = angular.module('list-module', []);     
spApp.controller('list-controller', function($scope, $http){  
  $http({  
    url: _spPageContextInfo.webAbsoluteUrl + "/_api/lists/getbytitle('QuestionAnswers')/items?$filter=Title eq "+id+"", //assuming web part is added on same site :)   
        method: "GET",  
        headers: { "Accept": "application/json;odata=verbose" }  
    }).then(function success(data) 
    {
      $scope.answers=data.data.d.results;
      $scope.answersCount=data.data.d.results.length;              
    },
      function error(data) 
    {

    });
});

<div ng-app="list-module">  
    <div ng-controller="list-controller">
      {{answersCount}}
    </div>
</div>
  • My bad..there was syntax error in my code..it is working perfectly now – Dheeraj Oct 13 '17 at 6:04
0

try with square brackets:

spApp.controller('list-controller', ["$scope", "$http", function($scope, $http){ ... }])

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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