Global Functions in AngularJs Hello everyone, I am going to share the code sample to create the global functions available in every controller. Here in AngularJs, have two options for creating global functions. i.e. 1. Define a service for global function. 2. Using run method for root scope . Here, I am going to use the $ rootScope and app.run() on initialization in AngularJs as given below example. The live demo link http://embed.plnkr.co/lQfOiX/preview //This is global functions for every controller. app.run( function ($rootScope) { $rootScope.myGlobalFunction = function () { }; }); The AngularJs code-sample var app = angular.module( 'myApp' , []); //This is global functions for every controller. app.run( function ($rootScope, $window) { $rootScope.myGlobalFunction = function () { //...
Angular, React, JavaScript, Java, PHP, SQL, C#, Vue, NodeJs, TypeScript and Interview Questions Answers