Reputation: 549
If in url parameter id is available then i want to call function.
.controller('repeatCtrl', function($scope,$state,$stateParams) { if($stateParams.id != ""){ //Here i want to call itemDetails function $scope.itemDetails(id); }; $scope.itemDetails = function(id) { // function body here!! alert(id); }; })
Upvotes: 3
Views: 9649
Reputation: 136134
You issue is you are calling a 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 i want to call itemDetails function
$scope.itemDetails(id);
};
})
Upvotes: 3