1.0.2 • Published 7 years ago

@vendasta/country-state-service v1.0.2

Weekly downloads
-
License
ISC
Repository
-
Last release
7 years ago

Country State Service

This provides a service for other components to use to retrieve country and state information.

Requirements

The Country State Service interface:

export interface CountryStateServiceInterface {
  getCountriesOptions(): Observable<Country[]>;
  getStatesOptions(countryCode: string): Observable<State[]>;
}

To implement the interface make a new service that implements the interface:

…
import {CountryStateServiceInterface, Country, State} from '@vendasta/country-state-service';

@Injectable()
export class CountryStateService implements CountryStateServiceInterface {
  …
  getCountriesOptions(): Observable<Country[]> {
    // Implement how the project will return the list of countries
  }
  getStatesOptions(countryCode: string): Observable<State[]> {
    // Implement how the project will return the list of states for the country
  }
}

Next you will need to provide your service as that interface (generally in app.module.ts)

import { CountryStateService } from './country-state.service';
import { CountryStateServiceInterfaceToken } from '@vendasta/country-state-service';
…
@NgModule({
  …
  providers: [
    CountryStateService, {provide: CountryStateServiceInterfaceToken, useExisting: CountryStateService}
  ],
})
  • Note: To be able to inject an interface, you will have to provide the InjectionToken and not the interface itself (CountryStateServiceInterfaceToken vs CountryStateServiceInterface).