what function(s) will be executed inside a angular controller

7 views
Skip to first unread message

Martin Bogar

unread,
Feb 16, 2018, 11:55:50 PM2/16/18
to Angular and AngularJS discussion
Suppose I have a angularJS (1.x) controller like

var app= angular.module("myModule");
app.controller("myCtrl", myCtrl);
myCtrl.$inject=['$scope', myService];
function myCtrl($scope, myService) {

    $scope.isOk = true;

   $scope.function1 = function() {
       ....
    }

    $scope.function2 = function() {
      ....
     }

}

********
Question: will ALL the methods inside this controller be executed when it is loaded ?  Or will them just be executed when they are invoked ?

Sander Elias

unread,
Feb 17, 2018, 12:49:37 AM2/17/18
to Angular and AngularJS discussion
Hi Martin,

None, only when invoked. There are a couple of special named ones that will get invoked if you defined them, the so-called life-cycle hooks. You can read about them in the component documentation.

Regards
Sander
Reply all
Reply to author
Forward
0 new messages