Skip to content

Commit

Permalink
Appcomonent.ts refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
MuSuAL committed May 29, 2021
1 parent 8eea469 commit abf0d8b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 41 deletions.
45 changes: 4 additions & 41 deletions frontend/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { OnInit } from '@angular/core';
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent implements OnInit, ControlValueAccessor {
export class AppComponent implements OnInit {
title = 'frontend';
projectComponents = [];
chipsControl = new FormControl('');
Expand All @@ -27,13 +27,9 @@ export class AppComponent implements OnInit, ControlValueAccessor {
hideRequiredControl = new FormControl(false);
floatLabelControl = new FormControl('auto');

//chips
@Input() opt: string[] = ["a","b"];

@ViewChild('parent', { read: ViewContainerRef }) container: ViewContainerRef;
onChange!: (value: string[]) => void;
@ViewChild(MatChipList)
chipList!: MatChipList;
value: string[] = [];


constructor(
fb: FormBuilder,
Expand All @@ -45,40 +41,7 @@ export class AppComponent implements OnInit, ControlValueAccessor {
floatLabel: this.floatLabelControl,
});
}
registerOnChange(fn: (_: any) => void): void {
this.onChange = fn;
}

propagateChange(value: string[]) {
if (this.onChange) {
this.onChange(value);
}
}
writeValue(value: string[]): void {
// When form value set when chips list initialized
if (this.chipList && value) {
this.selectChips(value);
} else if (value) {
// When chips not initialized
this.value = value;
}
}selectChips(value: string[]) {
this.chipList.chips.forEach((chip) => chip.deselect());

const chipsToSelect = this.chipList.chips.filter((c) =>
value.includes(c.value)
);

chipsToSelect.forEach((chip) => chip.select());
}

registerOnTouched(fn: any): void {
throw new Error('Method not implemented.');
}
setDisabledState?(isDisabled: boolean): void {
throw new Error('Method not implemented.');
}


getIfForwardLinkWorked() {
return this.forwardLinkWorked;
}
Expand Down
24 changes: 24 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"chart.js": "^3.2.1"
}
}

0 comments on commit abf0d8b

Please sign in to comment.