这是我的第一个angualr项目.我正在更新元素点击的输入值.我希望在更改此值时触发过滤管道.触发管道的逻辑是指令.这可能吗?
零件
<input id="filter-careers" placeholder="type your title here" type="text" [(ngModel)]="term" value="">
<div class="vacancy {{vacancy.department}}" *ngFor="let vacancy of vacancies | filter:term"
(click)="openModalContent(vacancy.description, vacancy.positionTitle, vacancy.department, vacancy.link)">
<p>{{vacancy.positionTitle }}</p>
</div>
Run Code Online (Sandbox Code Playgroud)
第二部分
<div class="department" *ngFor="let department of departments" appDepartmentsDirective [departmentName]="department.name" >
<div class="icon" [ngStyle]="{background: 'url(' + '../../assets/' + department.link + '.png' + ') center center no-repeat'}">
<img src="../../assets/{{department.link}}.svg" />
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
指示
import { Directive, HostListener, Input } from '@angular/core';
@Directive({
selector: '[appDepartmentsDirective]'
})
export class DepartmentsDirectiveDirective {
@Input() departmentName:string;
constructor() { }
@HostListener('click') …Run Code Online (Sandbox Code Playgroud)