Storing application configuration settings

前端 未结 5 664
你的背包
你的背包 2021-01-31 07:39

What is the best place to store application configuration settings in AngularJS? This could be things like application constants, lookups etc. which could be used both from cont

5条回答
  •  说谎
    说谎 (楼主)
    2021-01-31 08:32

    Add this to have access to a global variable

    app.run(function ($rootScope) {
        $rootScope.globalVariable = 'Amadou'; //global variable
    });
    

    Now if you want to use it from your controller

    function appNameCtrl($scope, $rootScope){
        $rootScope.globalVariable = 'Modji';
    }
    

    In you view

    My name is {{globalVariable}}
    

提交回复
热议问题