いくつかの定数に保存できる別の.jsファイルが必要です。app.jsファイルから別のファイルの定数にアクセスするにはどうすればよいですか?
このファイルの定数をapp.jsファイルで使用する必要があります。
私がこれに使用している構造と、私が遭遇した間違いは以下のようなものです。
この問題の原因と解決方法は何ですか?この状況をどうやって処理するのがいいですか? (doesntの問題 '値' または '定数')
"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);
}
]);
anglejs関連の質問に角タグを使用しないでください –
ただ編集しました、申し訳ありません。 – OkurYazar
@ Jota.Toledo助けてもらえますか? – OkurYazar