We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
export class AppComponent { form: FormGroup; ngOnInit() { this.form = new FormGroup({ input: new FormControl(false), }); } }
export class AppComponent { form: FormGroup; ngOnInit() { this.form = new FormGroup({ input: new FormControl({ disabled: true, value: '' }, []), }); } }
指令ts
import { NgControl } from '@angular/forms'; @Directive({ selector: '[disableControl]' }) export class DisableControlDirective { @Input() set disableControl( condition : boolean ) { const action = condition ? 'disable' : 'enable'; this.ngControl.control[action](); } constructor( private ngControl : NgControl ) { } }
html中使用 [disableControl],当然也可以传变量进去
[disableControl]
<form [formGroup]="form"> <input formControlName="input1" placeholder="输入框1" [disableControl]="true"> <input formControlName="input2" placeholder="输入框2" > </form>
The text was updated successfully, but these errors were encountered:
No branches or pull requests
方法1: 直接设置为false
方法2: 设置disabled 为 false
方法3 使用指令
指令ts
html中使用
[disableControl]
,当然也可以传变量进去The text was updated successfully, but these errors were encountered: