在我的index.html文件中,我有一个脚本需要从外部config.properties文件设置一些变量。该文件只包含一个JSON对象:
{
"appUrl": "http://myappurl.com",
"appId": "10"
}
在我的index.html文件中,我想做类似的事情:
<html ng-app="myApp" ng-controller="myController">
<head>
<script>
// adds script element with appUrl as a source
var url = "{{appUrl}}";
new_script_element.src= url + "myApp.js";
</script>
</head>
</head>
如何读取属性文件,将值转换为常量,并将常量传递给控制器以供使用?请具体说明应该创建/修改哪些文件,即:app.js(其中定义了“MyApp”模块),index.html和myController.js。知道在app.js中我当前的myApp.config看起来像这样:
也可能有所帮助myApp.config(function($routeProvider, $locationProvider) {...}