Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
863 views
in Technique[技术] by (71.8m points)

angular - Display employee in specific department foreign key

I'm building a web app using Angular + Typescript. And I have ASP.NET Core Web API, I have two components one is employee and another is department. I want to make a dropdown so if I select for example IT department, I got all employee in this department. I declared department as a foreign key in employee table.

Html Code

<div class="example-button-row">
    <mat-label>{{'::Departement' | abpLocalization}}</mat-label>
    <mat-select id="author-id" Name="departementId" autofocus (selectionChange)="showemployee($event.value)">
      <mat-option [value]="departement.id" *ngFor="let departement of departements$ | async">{{ departement.name }}</mat-option>
    </mat-select>
</div>

Typescript:

export class EmployeeComponent implements OnInit {
    departements$: Observable<DepartementLookupDto[]>; 
    constructor( public readonly list: ListService,
        private employeeService: EmployeeService) {this.departements$ = employeeService.getDepartementLookup().pipe(map((r) => r.items));
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can call endpoint for getting employee and the use FILTER on the resoult.

showemployee(filter:string)
{
  this.employeeService.getEmployee().subscribe(res=>
  {
     this.listOfEmloyee = res.filter(u => u.department == 'filter')
  })
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...