mardi 4 juillet 2017

Pattern to initialize a function when angular component launch

Recently I had initialize a function when the angular component launch.

I had seen this comment and I'd like to know if is it a good pattern or could be better declare the function and call it after such the code below:

angular.module('app').controller('control',[...,
  function(){
    ...
    var init = function () {
      //what i wish run on launch
    };

    // function call to launch
    init();

  }
)

or as mentioned in comment:

(function(){
    //code to run
}());

What do you have been used or even are there known problems when use this last approach?

Aucun commentaire:

Enregistrer un commentaire