Ich habe ein Problem mit einer ionischen App. Ich erstelle eine service.js
Datei, wo ich dieselbe Fabrik erstellen möchte.Ionic service.js funktionieren nicht
In meinem app.js
Ich habe diese Zeile:
angular.module('app', ['ionic', 'app.controllers', 'app.routes', 'app.directives','app.services'])
wo ich Controller, Routen laden, Richtlinien und Dienstleistungen.
Das ist mein services.js
angular.module('app.services', [])
.factory('MyService', function() {
return {
sayHello: function() {
return "HELLO";
}
}
});
Wo neue Fabrik MyService
mit einer Funktion sayHello genannt erstellen.
In meinem controller.js
Ich habe diesen Code
angular.module('app.controllers', ['app.services'])
.controller('iMontiCtrl', ['$scope', '$stateParams',
function ($scope, $stateParams, MyService) {
$messaggio = "Test";
alert($messaggio);
$scope.messaggio1 = MyService.sayHello();
alert($messaggio+"2");
}])
Diese Show Code nur alert($messaggio)
aber nicht alert($messaggio+"2")
Wenn ich Myservice.sayHello()
Kommentar ist es gut funktionieren.
ich überprüfen index.html
schließen auch ein:
<script src="js/app.js"></script>
<script src="js/controllers.js"></script>
<script src="js/routes.js"></script>
<script src="js/directives.js"></script>
<script src="js/services.js"></script>
Aber ich sehe Problem nicht.
Dank verwenden. Es funktioniert gut! –