在Angular 7中,如果表单控件没有指定name属性的值,可以使用以下方法访问该控件:
accessControl(control: any) {
console.log(control);
}
import { Component, ViewChild, ElementRef } from '@angular/core';
@Component({
selector: 'app-example',
template: `
`
})
export class ExampleComponent {
@ViewChild('myControl', { static: false }) myControl: ElementRef;
accessControl() {
console.log(this.myControl.nativeElement);
}
}
这些方法可以让您在没有指定name属性的情况下访问表单控件。