我需要一個單獨的.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