angularjs - Javascript Self Invoking functions in Angular controllers -


i use self invoking functions include javascript code inside angular controller (i think saw somewhere best practice). controller looks this:

(function() { // code })() 

i use gulp merge controllers 1 file. question this. mean of javascript code invoked , executed when application starts? if so, guess not approach. there solutions issue? comments? thanks

no, not code gets executed. when define angular modules

(function() {   'use strict';    angular     .module('mymodule', [])     .controller('mycontroller', ['$http', mycontrollerfunc]);    function mycontrollerfunc ($http) {     // ...   } })(); 

what gets executed angular methods register module , controller. actual controller logic in callback function, , gets called when controller invoked (e.g. router).

so, good, , wrapping code in anonymous functions idea keep, example mycontrollerfunc, out of global namespace.


Comments

Popular posts from this blog

php - Passing multiple values in a url using checkbox -

compilation - PHP install fails on Ubuntu 14 (make: *** [sapi/cli/php] Error 1) PHP 5.6.20 -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -