Ich brauche eine separate .js-Datei, die ich in einigen Konstanten speichern kann.Wie kann ich in meiner Datei app.js auf Konstanten in einer anderen Datei zugreifen?
Ich muss die Konstanten in dieser Datei in der Datei app.js verwenden.
Die Struktur, die ich für diesen und den Fehler verwende, den ich angetroffen habe, ist wie der folgende.
Was ist die Ursache und Lösung dieses Problems für Sie? Wie kann ich am besten mit dieser Situation umgehen? (Spielt keine Rolle 'Wert' oder 'constant')
"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.
});
Steuerung (in app.js)
MyApp.controller("AppController",
[
"$scope", "$rootScope", "globalValue", "globalConstant",
function($scope,
$rootScope,
globalValue,
globalConstant) {
debugger;
console.log(globalValue);
console.log(globalConstant);
}
]);
nicht das eckige Tag in angularjs verwandte Fragen –
gerade bearbeitet, tut mir leid, meine schlechte. – OkurYazar
@ Jota.Toledo Irgendwelche Hilfe oder ...? – OkurYazar