简体   繁体   中英

$injector:unpr angularjs when injecting a service in the controller

I am having trouble with injecting my service in angular that gives me $injector:unpr error. Here is my code:

(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; 
    }

// This is the controller.js file where I inject the service I created above

(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();
  }
}

Any idea what am I possibly missing ?

Thanks for the inputs folks. I think I was missing the registering the app.services in my main app module. Doing this solved the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM