AngularJS-service in separater Datei

Meine app.js enthält

var app = angular.module('myApp', []).
config(['$routeProvider', function ($routeProvider, $http) {
    ...
}]);

Service sieht aus wie

app.service('MyService', function () {
    addNums = function (text) {
        return text + "123";
    }
});

Und im Controller habe ich

function adminCtrl ($scope, MyService) {
    $scope.txt = MyService.addNums("abc");
};

Sind Sie alle in separaten Dateien. Das problem ist, dass ich bin immer ein Fehler
Unknown provider: MyServiceProvider <- MyService

Sieht aus wie ich bin, etwas falsch zu machen.

  • Sollten Sie verwenden this.addNums = function (text) statt addNums = function (text).
InformationsquelleAutor ChruS | 2012-11-15
Schreibe einen Kommentar