2017-06-14 110 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

相关问题