0

I am trying to build a very, very simple service and use it in angular, with all of my code listed below. But no matter what I try, I'm getting told ...

Unknown provider: userServiceProvider <- userService

I'm pulling my hair out with this, so I'm hoping experienced eyes can see what I'm missing..

app.js

(function () {
    angular.module('Application', [
        'kendo.directives',
        'ui.bootstrap',
        'ui.bootstrap.drawer',
        'ui.check',
    ]);
})();

identity.js

(function () {
    'use strict';

    var UserService = function ($http) {
        this.Find = function () {
            return this.$http.get("/member/identity").then(function (response) {
                return response.data;
            });
        }
    }

    angular
        .module('Application')
        .service('UserService', [UserService,"$http"]);
})();

controller.js

(function () {
    'use strict';

    var UserController = function (userService, $scope) {
        var _this = $scope;

        userService.Find().then(function (user) {
            _this.User = user;
        });
    };

    angular
        .module('Application')
        .controller('UserController',
            UserController, ['Application.UserService', "$scope"]
        );
})();

1 Answer 1

2

just change the sequence

angular
    .module('Application')
    .service('UserService', ["$http", UserService]);

angular
    .module('Application')
    .controller('UserController', ['Application.UserService', "$scope", UserController]
    );

dependencies to be injected comes before the function which defined the service/controller

also have the same case when defining and injecting the service as service names are case sensetive

Sign up to request clarification or add additional context in comments.

2 Comments

Hrnm, that doesn't seem to have fixed it.
Oh I see. So I was putting them in the wrong order in two places. That explains it. Thank you so much! I'll accept the answer as soon as stackoverflow lets me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.