Problem with angular js inject

Asked

Viewed 33 times

0

It’s been a while since I’ve been learning Angular and having some problems. I try to include a service (httpService), but an error occurs. My code:

Controller.js:

'use strict';

 var app = angular.module('ang-app');
  app.controller('User_Register_EditCtrl', user_register_edit);


  user_register_edit.$inject = ['httpService'];
  function user_register_edit(httpService){

    var ctrl = this;

    //variables


    //methods
    ctrl.backend = backend;
    ctrl.saveUser = saveUser;

    function backend(){
        a = httpService.post('backend.php', {nome: 'carlos', idade: '15'});
        console.log(a);
    }
    function saveUser(){
        $('#loading').show();
        setTimeout(function(){
            console.log('Saving...');
        }, 2000);
    }
}

Service.js:

   'use strict';

 var app = angular.module('ang-app');
 app.factory('httpService', httpService);

function httpService($http, httpUtils){
    var path = './ang-app_webservices';
    var http = {};
    http.get = get;
    http.post = post;

    function get(url, params){
        queryParams = httpUtils.convertToQueryParams(params);
        return $http({
            url: path + url + '?' + queryParams,
            method: 'GET'
        })
    }
    function post(url, data){
        return $http({
            url: path + url,
            method: 'POST',
            data: data
        })
    }
}

The mistake:

Error: $injector:unpr Unknown Provider

Unknown Provider: httpUtilsProvider <- httpUtils <- httpService

1 answer

0

Meteus, this problem occurs when Angular does not find a Provider/service/Factory following that order of the message. In your case from httpService angular found no service/Factory called httpUtils.

Check if it exists and is declared under that name.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.