AngularJs Global Constants Set and Get Variables

AngularJs Global Constants Set and Get Variables

AngularJs Global Constants Set and Get Variables

In this Post We Will Explain About is AngularJs Global Constants Set and Get Variables With Example and Demo.Welcome on infinityknow.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to How to set global variable of Session using AngularJS Example

In this post we will show you Best way to implement AngularJS Global Variables Constants and Values With Example, hear for Set global constants and variables in AngularJs with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

READ :  Redirect page after delay using AngularJS

Using the global root scope method AngularJs

Set global constants or variables app.js

// Set global constants or variables app.js
angular.module('liveApp', [
        'ngCookies',
        'ngResource',
        'ngSanitize',
        'ngRoute'
    ])
    .config(function ($routeProvider) {
        $routeProvider
            .when('/', {
                templateUrl: 'partials/main.html',
                controller: 'liveCtrl'
            })
            .otherwise({
                redirectTo: '/'
            });
    })
    .run(function ($rootScope) {
        $rootScope.mydataString = 41;
    });

Create a Main.js file using AngularJs

GET globalvariables in AngularJs main.js

// GET globalvariables in AngularJs main.js
angular.module('liveApp')
    .controller('liveCtrl', [
        '$scope', '$rootScope',
        function ($scope, $rootScope) {
            console.log($rootScope.mydataString);
        }
    ]);

Using the global constant method AngularJs

E-junkie: Sell digital downloads online

E-junkie Provides a Copy-paste buy-now, and cart buttons for selling downloads, codes and tangible products on any website, blog, social media, email and messenger!

Also see:

  1. The Top 10+ Best Webinar Software Platforms For 2020-2021
  2. Build Your Future Godaddy Careers And Jobs
  3. Introduction To Web Hosting Services

Set global constants variables app.js

// Set global constants variables app.js
angular.module('liveApp', [
        'ngCookies',
        'ngResource',
        'ngSanitize',
        'ngRoute'
    ])
    .constant('config', {
        mydataString: 41
    })
    .config(function ($routeProvider) {
        $routeProvider
            .when('/', {
                templateUrl: 'partials/main.html',
                controller: 'liveCtrl'
            })
            .otherwise({
                redirectTo: '/'
            });
    });

Create a Main.js file using AngularJs

READ :  Vuejs Simple Tooltip Plugin v-tooltip Example

GET global variables in AngularJs main.js

// GET global variables in AngularJs main.js
angular.module('liveApp')
    .controller('liveCtrl', [
        '$scope', 'config',
        function ($scope, config) {
            console.log(config.mydataString);
        }
    ]);

Example

I hope you have Got What is Set global constants in AngularJs And how it works.I would Like to have FeadBack From My Blog(infinityknow.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(infinityknow.com) Are Most Always Welcome.