0

enter image description here APP.controller('ListController', ['$rootScope', '$scope', function($rootScope, $scope) { $scope.$on('$viewContentLoaded', function() {
// initialize core components });}]);

function pageElements(){ 
      $('#tt-datatable').dataTable(); 
}

APP.controller('Acctbl',['$http',function($http){
    var accdata=this;
    accdata.item=[];
    $http({
        url:_spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('Account')/items",
        method: "GET",
        headers: {"Accept": "application/json;odata=verbose"}
     }).success(function(data){
        accdata.item=data.d.results;
     });
}

]);

I want to run pageElements after controller loaded , when i run on first

$scope.$on('$viewContentLoaded', function() {   

});}]);

I am getting datatables with no results found and again data is binding

4
  • you want to execute controller into pageElements function ? I think its not impossible Commented Feb 26, 2015 at 8:30
  • I Want to call Javascript function after Acctbl controller Commented Feb 26, 2015 at 8:40
  • Create a nested controller or create a directive Commented Feb 26, 2015 at 8:42
  • @pixelbits could you please give me small example . it will save lot of my time , Thanks in advance Commented Feb 26, 2015 at 8:49

1 Answer 1

0

To make the function pageElements() run after you get your results from the http-request, you need to move the function inside your controller. Then call it in the success-handler.

APP.controller('Acctbl',['$http',function($http){
    var accdata=this;
    accdata.item=[];
    $http({
         url:_spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('Account')/items",
         method: "GET",
         headers: {"Accept": "application/json;odata=verbose"}
    }).success(function(data){
         accdata.item=data.d.results;
         pageElements();
    });

    function pageElements(){ 
        $('#tt-datatable').dataTable(); 
    }
}
Sign up to request clarification or add additional context in comments.

2 Comments

I already did the same but i am getting "No data Available in table". Refer to attached picture
@Vamsikrishna, its difficult to debug with your code example. Create a jsFiddle, and i'll look at it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.