3

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);
        };
    })

7
  • What is the problem with above code? It should work..but if you want it to do in different way..please explain what you want Commented Jun 3, 2015 at 6:11
  • This code doesn't work function not call and in output display white screen.. i want to call function itself if condition true. Commented Jun 3, 2015 at 6:16
  • 1
    your if should be if($stateParams.id && $stateParams.id != "") Commented Jun 3, 2015 at 6:17
  • Thanks dear my problem solved.... i have call function after it's declaration. Commented Jun 3, 2015 at 6:21
  • 1
    Finally. Ans is call function after it's declaration and it's works.. Add ans i will close this.. Commented Jun 3, 2015 at 6:25

1 Answer 1

3

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);
    };
})

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.