我需要一个单独的.js文件,我可以存储在一些常量中。如何从我的app.js文件访问另一个文件中的常量?
我需要在app.js文件中使用此文件中的常量。
我正在使用的结构和我遇到的错误如下所示。
这个问题的原因和解决方法是什么?我怎样才能最好地处理这种情况? (并不重要 '值' 或 '恒定')
"Error: [$injector:unpr] Unknown provider: globalValueProvider <- globalValue <- AppController
的index.html
<script src="app/app.js" type="text/javascript"></script> //there it is
<script src="app/globalConstants.js" type="text/javascript"></script>
<script src="app/globalValues.js" type="text/javascript"></script>
app.js
var MyApp= angular.module("MyApp",
[
//is necessary?
//depency injection
...
]);
const.js
var MyApp= angular.module("MyApp");
MyApp.constant("globalConstant",
{
"data": "test" // all data, source, file whatever u say that's all.
});
value.js
var MyApp= angular.module("MyApp");
MyApp.constant("globalValue",
{
"data": "test" // all data, source, file whatever u say that's all.
});
控制器(在app.js)
MyApp.controller("AppController",
[
"$scope", "$rootScope", "globalValue", "globalConstant",
function($scope,
$rootScope,
globalValue,
globalConstant) {
debugger;
console.log(globalValue);
console.log(globalConstant);
}
]);
不要在angularjs中使用angular标签相关的问题 –
刚刚编辑,对不起我的坏。 – OkurYazar
@ Jota.Toledo任何帮助或...? – OkurYazar