2017-06-14 107 views
0

我需要一個單獨的.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); 
    } 
]); 
+0

不要在angularjs中使用angular標籤相關的問題 –

+0

剛剛編輯,對不起我的壞。 – OkurYazar

+0

@ Jota.Toledo任何幫助或...? – OkurYazar

回答

0

解決。檢查你的視圖腳本標籤。 app.js必須是最重要的。感謝@Mr_Perfect

+0

沒有任何問題好吧......我的意思是,我多次對你說過,但是不,讓我們感謝@Mr_Perfect:D,沒有難過的感覺,它只是有趣的 – koox00

+1

也謝謝你,最好的問候。 – OkurYazar

相關問題