ecmascript 6 - ES6 AngularJS 1 $inject Inheritence -
i have 3 child controllers extending single parent controller so:
class parentcontroller { constructor( $scope, $state ){ this.$scope = $scope; this.$state = $state; } } parentcontroller.$inject = [ '$scope', '$state' ]; // child class childacontroller extends parentcontroller { constructor( $scope, $state, aservice ){ super( $scope, $state ); this.aservice = aservice; } // ... common functions } childacontroller.$inject.push( 'aservice' ); // child b class childbcontroller extends parentcontroller { constructor( $scope, $state, bservice ){ super( $scope, $state ); this.bservice = bservice; } } childbcontroller.$inject.push( 'bservice' );
my issue there reference kept $inject
array. meaning childb's 3rd dependency aservice
instead of bservice
.
so children have same following inject array
$inject => [ '$scope', '$state', 'aservice', 'bservice' ]
instead of own.
is there nice way around this? or have create sort of provider service decide service pass on?
they're going doing exact same task data different service, i'd try keep inheritance structure.
how using copy in child controllers?
childacontroller.$inject = [...parentcontroller.$inject, 'aservice']; childbcontroller.$inject = [...parentcontroller.$inject, 'bservice'];
Comments
Post a Comment