- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在使用 Angular CLI。我想制作一个自动完成表单,查看所有值(不像 angular.io 的例子那样做一个“开始于”)。
我设法让它与 [formControl]
一起工作,但我想将它插入到 FormGroup
中。所以我认为将它与 formControlName
一起使用(同时使用 formControlName
和 [formControl]
)意味着我没有从我的形式。
这是我当前的代码,但过滤器存在问题。谢谢你的帮助
component.html:
<form [formGroup]="tumeurForm" (ngSubmit)="onSubmitForm()">
<mat-form-field appearance="outline">
<mat-label>Diagnostic : inscription de la tumeur</mat-label>
<input
matInput
type="text"
formControlName="localisation"
[matAutocomplete]="auto"/>
<mat-autocomplete autoActiveFirstOption #auto="matAutocomplete">
<mat-option *ngFor="let option of filteredOptions | async" [value]="option">
{{ option }}
</mat-option>
</mat-autocomplete>
</mat-form-field>
</form>
component.ts:
export class DiagnosticDialogComponent implements OnInit {
options = [
"(C00) Néoplasie maligne de la lèvre",
"(C00.0) Lèvre supérieure, bord libre",
"(C00.1) Lèvre inférieure, bord libre"
];
patientid: string;
public tumeurForm: FormGroup ;
filteredOptions: Observable<string[]>;
constructor(private formBuilder: FormBuilder) { }
ngOnInit() {
this.initForm();
this.filteredOptions = this.tumeurForm.valueChanges.pipe(
startWith(""),
map(val => this.filter(val))
);
}
filter(val: string): string[] {
return this.options.filter(option => {
return option.toLowerCase().match(val.toLowerCase());
});
}
initForm() {
this.tumeurForm = this.formBuilder.group({
localisation: ['', Validators.required]
});
}
onSubmitForm() {
const localisation = this.tumeurForm.get('localisation').value;
const Patientid = this.patientid;
const newDiagnostic = new Diagnostic(localisation, Patientid);
this.diagnosticsService.CreateDiagnostic(newDiagnostic);
}
}
最佳答案
(如果我理解正确的话)
您正在对 FormGroup
的 .valueChanges
进行管道传输。但是您需要在 FormControl
上执行此操作。
所以代替
this.filteredOptions = this.tumeurForm.valueChanges.pipe(
startWith(""),
map(val => this.filter(val))
);
这样做:
this.filteredOptions = this.tumeurForm.controls['localisation'].valueChanges.pipe(
startWith(""),
map(val => this.filter(val))
);
关于angular - FormGroup CustomFilter 中的 Mat-AutoComplete,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50928851/
我有一个父组件,它是主要的 FormGroup .在此 组件我有一个子组件, . 子组件有一个 *ngIf="some-conditional" ,在子组件内部,我有一个快速填充按钮,它基本上是 pa
我找到了这个答案,它展示了如何将表单控件添加到父表单: Reuse components in angular2 model driven forms 但我希望能够像这样将新的 formGroup 添
我在 Plunkr 上有一个 Angular 2 RC4 基本表单示例,它似乎抛出以下错误(在 Chrome DEV 控制台中) 这是笨蛋 https://plnkr.co/edit/GtPDxw?p
这个问题在这里已经有了答案: How to use formControlName and deal with nested formGroup? (4 个答案) 关闭 3 年前。 我有这个用于 a
我正在尝试将 formGroup 添加到我的整体表单中,条件是在我的情况下特定字段属于某种类型。我添加此 formGroup 的函数如下所示: initSocial() { const
情况: 我正在尝试在我的 Ionic 2 应用程序中创建一个非常简单的登录表单。 无论我尝试什么,我都会不断收到此错误: formGroup expects a FormGroup instance.
在我的 Angular 2 组件中,我使用带有 18 个 AbstractControl 的 Formgroup。用户可以编辑从数据库加载的个人资料。我想添加一个 Reset 按钮来将表单重置为其原始
我是 Angular 2 的新手,无法解决这个问题即使在阅读了其他堆栈溢出答案之后也是如此。 我刚刚开始学习 Angular react 形式,想尝试第一个例子,但被卡住了。请帮忙。 这是 HTML
我在 Angular 4 中创建了一个 formGroup,其中用户和组织存储在对象中。现在我想使用这两个对象填充我的表单组。在我的 ts 中,我做了以下事情: createForm(user: an
我了解错误的根源,我正在测试的组件需要将 FormGroup 传递到它的 @Input() 表单:FormGroup。我只是不知道如何在测试此组件时传入一个。 当我调用 fixture.detectC
我不确定这是否是一个错误,几乎 90% 肯定不是,但我想知道发生这种情况背后的逻辑。 我有一个组件,假设我在组件初始化时初始化一个 FormGroup。 export class FooCompone
我有一个定义 FormGroup 的 Angular 组件,它有一个嵌套的 FormGroup 作为它的控件之一。 子 FormGroup 作为 @Input 参数传递给子 component,并且在
我正在 Angular 2 中创建一个表单。我的目标是从 API 获取数据并将其传递到表单中以进行编辑。但是,我遇到了这个错误: EXCEPTION: Uncaught (in promise): E
我有第二种形式。我需要填写来自银行的日期字段,一个 json 文件。在 populateFields 方法中,我得到一个包含将要填充的数据的参数。但是,它只填充itens的值,即数组内部的描述,它不执
选择验证时是否有任何首选方式 myForm.controls['name'].valid myForm.get('name').valid 因为两者似乎只是在句法上有所不同,但实现了相同的目标。 Na
我在使用 Angular 2 表单时遇到了一些问题,我在我的项目中成功地实现了一些表单,当我尝试添加这个表单时,我的 Angular Cli 出现了错误:类型“FormGroup”不可分配给类型“ty
我的情况很简单。有一个包含两个字段的 html 表单: 名字 姓氏 我希望在用户更改 firstName 时更改 lastName。我通过 Angular (8) 中可观察到的 valueChange
我有以下模板。我正在尝试掌握响应式表单,但遇到了问题。 First N
我目前正在使用 Angular 6 创建一个带有 Reactive Form 的 Accordion。我也在使用 primeNG 的 Accordion 模块。 基于对象(cuList),将动态创建F
在 StackOverflow 的其他示例中,有很多关于在 FormArrays 中使用 FormGroups 的问题。但我的问题恰恰相反。 FormArrays 有一个 push 方法,这使得很多事
我是一名优秀的程序员,十分优秀!