Skip to content

Commit

Permalink
fix(lib): solved minor bug #35
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyNahas committed Oct 4, 2020
1 parent 62ca478 commit 7ade997
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<input (blur)="onBlur()" (input)="inputChanged($event?.target?.value)" [class]="class"
[formControl]="countryFormControl" [matAutocomplete]="countryAutocomplete"
[placeholder]="placeHolder"
[readonly]="readonly" [value]="value?.name" aria-label="country"
[readonly]="readonly" [value]="this.value?.name" aria-label="country"
matInput type="text">
<mat-progress-bar *ngIf="this.loadingDB || this.loading" mode="buffer"></mat-progress-bar>
<mat-autocomplete #countryAutocomplete="matAutocomplete" (opened)="autocompleteScroll()"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export class MatSelectCountryComponent implements OnInit, OnChanges, OnDestroy,
return this._value;
}

@Input()
set value(value: Country) {
this._value = value;
this.propagateChange(this._value);
Expand All @@ -98,8 +99,7 @@ export class MatSelectCountryComponent implements OnInit, OnChanges, OnDestroy,
this.loadingDB = true;
this._importLang(this.i18n)
.then((res) => {
console.log('result', res);
console.log('countries', this.countries);
// console.log('countries', this.countries);
if (!this.disabled) {
this.countryFormControl.enable();
}
Expand All @@ -119,7 +119,7 @@ export class MatSelectCountryComponent implements OnInit, OnChanges, OnDestroy,
}

ngOnChanges(changes: SimpleChanges) {
console.log('changes', changes);
// console.log('changes', changes);
if (changes.country) {
if (changes.country.currentValue) {
const newValue = changes.country.currentValue.toUpperCase();
Expand Down Expand Up @@ -155,8 +155,10 @@ export class MatSelectCountryComponent implements OnInit, OnChanges, OnDestroy,
}

writeValue(obj: any): void {
console.log('writeValue');
if (obj) {
this.value = obj;
console.log('writeValue done', this.value);
}
}

Expand Down
12 changes: 7 additions & 5 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -471,11 +471,13 @@ <h2 class="div-ex2">Loading countries (e.g: Http...)</h2>
<h2 class="div-ex2">Usage with Reactive Forms</h2>

<div fxLayoutAlign="center">
<mat-select-country appearance="outline"
label="Country"
[formControl]="countryFormControl"
(onCountrySelected)="onCountrySelected($event)">
</mat-select-country>
<form [formGroup]="countryFormGroup">
<mat-select-country appearance="outline"
label="Country"
formControlName="country"
(onCountrySelected)="onCountrySelected($event)">
</mat-select-country>
</form>
</div>

<markdown src="assets/md/e2.md"></markdown>
Expand Down
7 changes: 6 additions & 1 deletion src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ export class AppComponent implements OnInit {
ngOnInit(): void {

this.countryFormGroup = this.formBuilder.group({
country: []
country: [{
name: 'Deutschland',
alpha2Code: 'DE',
alpha3Code: 'DEU',
numericCode: '276'
}]
});

this.countryFormGroup.get('country').valueChanges.subscribe(country => console.log('this.countryFormGroup.get(\'country\').valueChanges', country));
Expand Down

0 comments on commit 7ade997

Please sign in to comment.