javascript - angular inject $http to service -


i use inject inject $http .factory here code:

'use strict'; app.factory('myservice', myservice);  function myservice () {   let service = {     myfunc: myfunc,     };   return service; }  myfunc.$inject = ['$http']; function myfunc ($http) {     $http.get('api/data')     .success((res) => {       return res;     })     .error((e) => {       console.log('error' + e.message);     }); } 

but, when call function have error: typeerror: e.get not function. missed? thank's.

i reconfigure app follows:

(function () {     "use strict";      angular.module('app').factory('myservice', myservice);      myservice.$inject = ['$http'];     function myservice($http) {          function myfunc () {             $http.get('api/data')             .then(function(success){                return response.data;             }, function (failure){                return failure;             });         }          return {            myfunc: myfunc         }        } })(); 

what scope 'myfunc' 'myservice' factory. controller, can call myfunc() determined return statement. basically, issue understanding scope. wrapped entire factory closure , made minification safe you. hope helps!


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -