角度服务投掷"Unknown Provider"



我在这上面旋转我的轮子。我正在尝试向我的控制器提供此服务的实例。当我运行它时,我得到

JavaScript运行时错误:[$injector:unp]未知提供程序:app.services.GithubServiceProvider<-app.services.GithubService&lt-app.githubViewer.UserController

以下是部分:

  1. 服务本身

    module app.services {
    'use strict';
    export interface IGithubService {
    getUser(username: string): ng.IPromise<any>;
    }
    export class GithubService implements IGithubService {
    githubUrl: string = 'https://api.github.com/';
    static $inject = ['$http'];
    constructor(private $http: ng.IHttpService) {
    }
    getUser(username: string): angular.IPromise<any> {
    return this.$http.get(this.githubUrl + "users/" + username)
    .then(response => response.data);
    }
    }
    angular
    .module('app.services')
    .service('app.services.GithubService', GithubService);
    

    }

  2. 控制器

    module app.githubViewer {
    'use strict';
    interface IUserControllerScope { //scope definitions
    }
    class UserController implements IUserControllerScope {
    static $inject = ['app.services.GithubService', '$route'];
    constructor(githubService: app.services.IGithubService, $route: ng.route.IRouteService) {
    //...
    }
    }
    angular
    .module('app.githubViewer')
    .controller('app.githubViewer.UserController', UserController);
    

    }

Update,我在这里查看了这个常见问题列表,看起来一切都很正常。代码如下:

这是我的主要模块声明:

((): void => {
'use strict';
angular
.module('app', [
'app.core',
'app.services',
/*
*Feature Modules
*/
'app.githubViewer'
]);
})();

这是服务模块声明:

((): void => {
'use strict';
angular
.module('app.services', []);
})();

我已经进行了三次检查,以确保脚本已添加到页面中。

请告诉我,如果还有什么我应该张贴在这里。我是Angular和TypeScript的初学者。

您必须将app.services声明为app.githubViewer的依赖项

angular
.module('app.githubViewer', ['app.services'])

最新更新