找到你要的答案

Q:Application properties in AngularJs

Q:在AngularJs的应用性能

To maintain the application properties like BaseURL's, we used to create a .properties file and retrieve it whenever it is necessary in Java applications. In front-end angularJS application I can create a .json file and invoke it using $http.get() method.
Can I use angularJS constants for this functionality instead of making a $http call? Will there be any security issue if I use URL's in AngularJS constants?

To maintain the application properties like BaseURL's, we used to create a .properties file and retrieve it whenever it is necessary in Java applications. In front-end angularJS application I can create a .json file and invoke it using $http.get() method.
Can I use angularJS constants for this functionality instead of making a $http call? Will there be any security issue if I use URL's in AngularJS constants?

answer1: 回答1:

In our projects we used to put all such configuration in one JSON file, i.e.

{
  "BASE_URL": "/myApp",
  "VERSION": "1.0"
}

and then, convert this file during build phase into angular module, i.e.:

agnular.module("myProject.config", [])
.constant("BASE_URL", "/myApp")
.constant("VERSION", "1.0";

and, finally, append the source code of the app to this config module with appropriate dependency:

angular.module("myProject", ["myProject.config"]);

There are Grunt and gulp plugins that can automate it for you.

在我们的项目,我们习惯把所有这样的配置在一个JSON文件,即

{
  "BASE_URL": "/myApp",
  "VERSION": "1.0"
}

然后,将该文件在生成阶段转换成角模块,即:

agnular.module("myProject.config", [])
.constant("BASE_URL", "/myApp")
.constant("VERSION", "1.0";

最后,将应用程序的源代码附加到这个配置模块中,并具有适当的依赖性:

angular.module("myProject", ["myProject.config"]);

有呼噜声和吞咽的插件,可以自动为你。

angularjs  properties  base-url