0

I am getting error method1 () is undefined. What is the proper way to invoke a method during init?

 gdmsDashboard.controller('DashboardController', '$scope') {

        $scope.Msg = "";

        (function init() {
            $scope.method1 ();
            method1 ();
            this.method1 ();

        })();

        $scope.method1 = function () { 
          //
        }
}
6
  • what do you mean by init, run method ? Commented Jul 22, 2015 at 15:51
  • You need to learn variable hoisting concept Commented Jul 22, 2015 at 15:52
  • 1
    $scope.logOut function needs to be created first before you can call it using the controller setup you have. Commented Jul 22, 2015 at 15:53
  • I guess the question is why are you initing a logout function? Are you logging the user out when the controller is called? Commented Jul 22, 2015 at 15:55
  • 1
    You need to define the $scope.logout before the iife statement. Commented Jul 22, 2015 at 16:05

1 Answer 1

1

You need to understand variable hoisting concept

Just to make your code work do this

$scope.method1 = function () { 
          //
        }
(function init() {
            $scope.method1();
})();
Sign up to request clarification or add additional context in comments.

Comments

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.