$ injector:在控制器中注入服务时unpr angularjs

时间:2016-03-24 17:18:06

标签: javascript angularjs

我在使用angular注入我的服务时出现问题,这给了我$ injector:unpr错误。这是我的代码:

(function () {

/**
 * This is a service to perform the backend REST calls for a Release
 */

'use strict';

angular.module('app.services')
        .service('ReleaseService', ReleaseService);
ReleaseService.$inject = ['$http'];
function ReleaseService () {

    var releaseService = {};

    var releasesUrl = 'http://localhost:8080/api/releases';

    releaseService.releases = getReleases;

    return releaseService;  // return the release service object to the controller

    /**
     * Get the list of the releases. Does an HTTP GET request to the backend
     * @returns {Array} of releases to the caller of the service
     */
    function getReleases(){
        var releases = [];
        $http.get(releasesUrl).then(function(responseData){

            //check the status from the response data.
            if(responseData.status !== 200){
                alert('The request could not be completed. Please try again');
            } else{
                // else, Parse the json data here and return to the service caller
                for(var release in responseData.data){
                    releases.push({slug: release, data: responseData.data[release]});
                }
            }
        });
        return releases; 
    }

//这是我注入上面创建的服务的controller.js文件

(function (){

angular.module('app.uploadedReleases')
        .controller('UploadedReleasesController', UploadedReleasesController)
        .controller('ModalController', ModalController);


UploadedReleasesController.$inject = ['$log', '$scope', '$modal', 'ReleaseService', 'TrackService'];
function UploadedReleasesController ($log, $scope, $modal, releaseService, TrackService){

function init(){

        var something = releaseService.releases();
  }
}

知道我可能错过了什么吗?

1 个答案:

答案 0 :(得分:1)

感谢输入人员。我想我错过了在我的主app模块中注册app.services。这样做解决了这个问题。