angular - Extending Angular2+ services -


i trying write 'base' service empty methods should overridden other developers writing 'adapters' different back-end systems

here 'base' authentication service:

import { injectable } '@angular/core'; import { http} '@angular/http'; import {constants} '../../constants/constants';   @injectable() export class apiauthserviceprovider {    constructor(public http: http) {     console.log('hello base class apiauthserviceprovider provider');    }    getversion(credentials): promise <any> {     throw constants.not_implemented;   }    gettoken (credentials): promise <any> {     throw constants.not_implemented;   }    getcredentials(): {     // stuff generic     // , part of base impleementation   }   } 

here proposed adapter extends service specific backend

import { injectable } '@angular/core'; import { http , urlsearchparams} '@angular/http'; import 'rxjs/add/operator/map'; import 'rxjs/add/operator/topromise'; import {constants} '../../../constants/constants'; import {apiauthserviceprovider} '../../../providers/api-auth-service/api-auth-service';   @injectable() export class zmapiauthserviceprovider extends apiauthserviceprovider {    constructor(public http: http) {     super(http);     console.log('hello zmapiauthserviceprovider provider');    }    getversion(credentials): promise <any> {     return this.http.get (credentials.url+'/api/host/getversion.json')     .topromise()   }     gettoken(credentials): promise <any> {    // stuff  } } 

here how associating adapter service in app.component.ts

import {apiauthserviceprovider} '../providers/api-auth-service/api-auth-service' import {constants} '../constants/constants';  // classes adapters in use import {zmapiauthserviceprovider} '../adapters/zoneminder/providers/zm-api-auth-service';  @component({   templateurl: 'app.html',   providers: [     {provide: apiauthserviceprovider, useclass: zmapiauthserviceprovider}] }) 

and finally, invocation in constructor of app.components.ts

constructor(public auth: apiauthserviceprovider) { this.auth.gettoken(credentials) } 

trying run produces whole bunch of errors:

  • individual declarations in merged declaration 'apiauthserviceprovider' must exported or local.
  • import declaration conflicts local declaration of 'apiauthserviceprovider'.
  • module '"xxx/src/adapters/zm/providers/zm-api-auth-service"' has no exported member 'zmapiauthserviceprovider'.

am approaching incorrectly? thanks.

okay, have no idea why not working when posted - it's possible did not save something!

this approach works - either a) magic b) omission save

i'll go magic.


Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -