When it comes to initializing variables in AngularJS, there are better methods than using ng-init;
ng-init="loader(); firstName = 'John'"
You can use constants or values for initializing variables instead;
Check out the official Angular documentation for more information.
For example, you can use constants like this:
var app = angular.module('myApp', []);
app.constant('appName', 'Application Name');
app.controller('TestCtrl', ['appName', function TestCtrl(appName) {
console.log(appName);
}]);
Or utilize values like so:
var app = angular.module('myApp', []);
app.value('usersOnline', 0);
app.controller('TestCtrl', ['usersOnline', function TestCtrl(usersOnline) {
console.log(usersOnline);
usersOnline = 15;
console.log(usersOnline);
}]);
Another good solution is to use services;
Check out this Stack Overflow thread for insights on using rootScope and service methods.
Thank you,