This package has been deprecated

Author message:

Moved to @vendasta/core

@vendasta/country-state-service
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

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).

Readme

Keywords

none

Package Sidebar

Install

npm i @vendasta/country-state-service

Weekly Downloads

0

Version

1.0.2

License

ISC

Last publish

Collaborators

  • vendasta