How to call function in controller in angularjs? -


if in url parameter id available want call function.

      .controller('repeatctrl', function($scope,$state,$stateparams) {         if($stateparams.id != ""){             //here want call itemdetails function              $scope.itemdetails(id);         };         $scope.itemdetails = function(id) {             // function body here!!             alert(id);         };     })  

you issue calling function before making declaration of it.

.controller('repeatctrl', function($scope,$state,$stateparams) {     $scope.itemdetails = function(id) {         // function body here!!         alert(id);     };     if($stateparams.id && $stateparams.id != ""){         //here want call itemdetails function          $scope.itemdetails(id);     }; }) 

Comments