angularjs - Using Angular to Inject into non-Angular Objects -
is there way provide non-angular injection target angular $injector such angular constructs $http, $scope, $location or $q can injected it?
//non-angular injection container var injectiontarget= { $http:undefined, $scope:undefined } //means inject target - part in question var injector = angular.injector(); injector.injectinto( injectiontarget, ["$http", "$scope"]);
i'm having hardest time finding info on how accomplish assume sought-after feature.
i think easiest way register objects services module.
var myobject = {} //defined elsewhere or here empty app.service(‘areferencename’, function($http){ myobject.$http = $http; return myobject; });
this have double effect of setting properties want on object, , making accessible angular needed. it's pretty simple block of code. note implication though service singleton angular's perspective. if need class many instances, you'll wanting factory.
Comments
Post a Comment