From b3ecbb3dc5e0e76b5c4b3a628ba34649c86e445d Mon Sep 17 00:00:00 2001 From: Anthony Nahas Date: Sun, 30 Aug 2020 21:11:17 +0200 Subject: [PATCH] fix(lib): ability to predefince specific countries #12 #20 --- .../select-country/package.json | 12 ++++----- .../src/lib/mat-select-country.component.ts | 4 +-- .../src/lib/mat-select-country.module.ts | 5 +++- src/app/app.component.html | 1 + src/app/app.component.ts | 27 +++++++++++++++++++ 5 files changed, 40 insertions(+), 9 deletions(-) diff --git a/projects/angular-material-extensions/select-country/package.json b/projects/angular-material-extensions/select-country/package.json index 64da207..140d26a 100644 --- a/projects/angular-material-extensions/select-country/package.json +++ b/projects/angular-material-extensions/select-country/package.json @@ -48,12 +48,12 @@ "test:watch": "../../../node_modules/.bin/jest --coverage --watch" }, "peerDependencies": { - "@angular/common": "^9.1.12", - "@angular/core": "^9.1.12", - "@angular/forms": "^9.1.12", - "@angular/platform-browser": "^9.1.12", - "@angular/cdk": "~9.2.4", - "@angular/material": "~9.2.4", + "@angular/common": "^10.0.0", + "@angular/core": "^10.0.0", + "@angular/forms": "^10.0.0", + "@angular/platform-browser": "^10.0.0", + "@angular/cdk": "~10.1.0", + "@angular/material": "~10.1.0", "rxjs": "^6.6.0" }, "engines": { diff --git a/projects/angular-material-extensions/select-country/src/lib/mat-select-country.component.ts b/projects/angular-material-extensions/select-country/src/lib/mat-select-country.component.ts index 864fe2a..29f92a4 100644 --- a/projects/angular-material-extensions/select-country/src/lib/mat-select-country.component.ts +++ b/projects/angular-material-extensions/select-country/src/lib/mat-select-country.component.ts @@ -19,7 +19,7 @@ export interface Country { /** * @author Anthony Nahas * @since 11.19 - * @version 1.0 + * @version 2.1.0 */ @Component({ selector: 'mat-select-country', @@ -45,12 +45,12 @@ export class MatSelectCountryComponent implements OnInit, OnChanges, ControlValu @Input() nullable: boolean; @Input() readonly: boolean; @Input() class: string; + @Input() countries: Country[] = COUNTRIES_DB; @Output() onCountrySelected: EventEmitter = new EventEmitter(); countryFormControl = new FormControl(); - countries: Country[] = COUNTRIES_DB; filteredOptions: Observable; propagateChange = (_: any) => { diff --git a/projects/angular-material-extensions/select-country/src/lib/mat-select-country.module.ts b/projects/angular-material-extensions/select-country/src/lib/mat-select-country.module.ts index d970a67..4b8f4c0 100644 --- a/projects/angular-material-extensions/select-country/src/lib/mat-select-country.module.ts +++ b/projects/angular-material-extensions/select-country/src/lib/mat-select-country.module.ts @@ -19,14 +19,17 @@ import {COUNTRIES_DB} from './db'; declarations: [MatSelectCountryComponent], imports: [ CommonModule, + + // Forms FormsModule, ReactiveFormsModule, + + // Material MatButtonModule, MatMenuModule, MatInputModule, MatAutocompleteModule, MatIconModule - // FlexLayoutModule ], exports: [MatSelectCountryComponent] }) diff --git a/src/app/app.component.html b/src/app/app.component.html index 0b1a5dd..9974076 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -435,6 +435,7 @@

Usage

diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 4cb4839..64b0c75 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -15,6 +15,33 @@ export class AppComponent implements OnInit { countryFormControl = new FormControl(); countryFormGroup: FormGroup; + predefinedCountries: Country[] = [ + { + name: 'Germany', + alpha2Code: 'DE', + alpha3Code: 'DEU', + numericCode: '276' + }, + { + name: 'Greece', + alpha2Code: 'GR', + alpha3Code: 'GRC', + numericCode: '300' + }, + { + name: 'France', + alpha2Code: 'FR', + alpha3Code: 'FRA', + numericCode: '250' + }, + { + name: 'Belgium', + alpha2Code: 'BE', + alpha3Code: 'BEL', + numericCode: '056' + }, + ]; + constructor(angulartics2GoogleAnalytics: Angulartics2GoogleAnalytics, private formBuilder: FormBuilder) { angulartics2GoogleAnalytics.startTracking();