更新时间:2023-02-13 10:39:01
终于解决了!
Finally solved !!!
这可以通过将服务注入子组件并执行自动完成功能来完成-[重新设计的一种方法] 在那边[我还没有实现,但这会起作用,因为它只是部门字段的副本]
This can be done-[one way of doing by redesigning] , by injecting the service into child component and doing the autocomplete feature over there [i haven't implemented this, but this will work as it just copy of department field]
在create-doiser.component.html
in create-doiser.component.html
<!-- </div> -->
<mat-autocomplete #thematicAutoComplete="matAutocomplete" [displayWith]="displayThematique">
<mat-option *ngFor="let thematique of filteredThematiques | async" [value]="thematique">
<span> {{thematique.code}} </span>
<span> - </span>
<span> {{thematique.libelle}} </span>
</mat-option>
</mat-autocomplete>
在autocomplete.component.html
in autocomplete.component.html
<mat-form-field style="display:block;transition:none ">
<div fxLayout="row">
<input matInput placeholder="Thématique" [matAutocomplete]="autoCompleteControl" (optionSelected)="test($event)" tabindex="{{tabIndex}}">
<div class="mat-select-arrow-wrapper" (click)="focus()">
<div class="mat-select-arrow" [ngClass]="{'mat-select-arrow-down': !autoCompleteControl.isOpen, 'mat-select-arrow-up': autoCompleteControl.isOpen}"></div>
</div>
</div>
</mat-form-field>
在autocomplete.component.ts
in autocomplete.component.ts
in set value emit the value to parent
this.em.emit(value);
create-dosier.component.ts
create-dosier.component.ts
this.thematique = new FormControl( ['', [Validators.required, this.thematiqueValidator]]
);
this.formDossier.addControl('thematique',this.thematique);
call(event){
this.thematique.setValue(event);
this.thematique.validator=this.thematiqueValidator();
this.thematique.markAsTouched();
this.thematique.markAsDirty();
}
}
这将解决所有问题,如果您要我推送到github,请让我知道. 希望这可以帮助 !!!! 谢谢!!
this will resolve all the issues, Please let me know if you want me to push to github .. Hope this helps !!!! Thanks !!
更新: 自动完成,提示现在一切正常.
UPDATE: Auto complete , mat-hint now everything is working..
我了解您不希望输入和mat-form-field在一起
I understand that you don't want input and mat-form-field to be together
但是如果只是让mat-hint动态显示[取决于 在 formcontrol values],我们可以将formcontrol从父级传递到子级 甚至消除了从中发出输入值的必要性 孩子对父母 在父组件中设置值,[mat-hint字段保留在父组件本身中]
but if it is just for mat-hint to show dynamically[which is depending on formcontrol values], we can pass the formcontrol from parent to child which even eliminates the necessity of emitting the input value from child to parent setting the value in parent component and [mat-hint field stays in the parent component itself]