AngularJS/Typescript - Access $http in unregisterd base service -
i have multiple services, extend baseservice class so:
module app.services { export class postservice extends baseservice { constructor() { super('post'); } } export var app:ng.imodule = app || angular.module('app.services.post'); app.service('postservice', postservice); } in baseservice, make requests using angularjs's provided $http tool. baseservice not registered angularjs module (it's typescript class registered services extend):
module app.services { export class baseservice { protected $http: any; baseroute:string; constructor(baseroute:string) { if (baseroute.indexof('api/') === 0) { this.baseroute = baseroute; } else { this.baseroute = 'api/' + baseroute; } } get(id: number) { this.$http.get... } } so postservice extends baseservice. how can gain access $http in scenario? ideally basecontroller handle acquiring $http of it's child services don't have send $http through. want handle setting $http , using in basecontroller. feel should able inject somehow:
static $inject = ['$http'];
but haven't had luck that.
use bootstrap function $injector , put on window https://docs.angularjs.org/guide/bootstrap.
then use $injector.get('$http') anywhere want in code.
Comments
Post a Comment