相关疑难解决方法(0)

对于HTML表单输入字段,disabled ="disabled"和readonly ="readonly"之间的区别是什么?

我已经对此有所了解,但我似乎无法找到关于不同浏览器如何处理事物的任何信息.

html cross-browser

398
推荐指数
5
解决办法
21万
查看次数

如何在Angular2 Typescript中更改HTML元素readonly和required属性?

对于我的一些组件,我想改变输入字段readonly和来回的必需属性.

我已经设法获得一个正在运行的代码,它可以根据需要更改它们,但问题是它只适用于readonly,但似乎没有按要求工作:虽然元素属性更改为所需的Angular2仍然认为fieldCtrl是有效的.

这是我的plunker,我在这里说明了这个问题:https://plnkr.co/edit/Yq2RDzUJjLPgReIgSBAO?p = preview

//our root app component
import {Component} from 'angular2/core'

@Component({
  selector: 'my-app',
  providers: [],
  template: `
    <div>
    <form #f="ngForm">
      <button type="button" (click)="toggleReadOnly()">Change readonly!</button>
      <button type="button" (click)="toggleRequired()">Change required!</button>
      <input id="field" [(ngModel)]="field" ngControl="fieldCtrl" #fieldCtrl="ngForm"/>
      {{fieldCtrl.valid}}
    </form>
    </div>
  `,
  directives: []
})
export class App {
  constructor() {
    this.name = 'Angular2'
  }

  toggleRequired(){
    this.isRequired = !this.isRequired;
    var fieldElement = <HTMLInputElement>document.getElementById('field');
    if (this.isRequired){
      fieldElement.required = true;
      this.field = "it's required now";
    }
    else{
      fieldElement.required = false;
      this.field = …
Run Code Online (Sandbox Code Playgroud)

typescript angular

25
推荐指数
2
解决办法
3万
查看次数

Angular 6 FormGroup.disable() 方法不适用于我的模板驱动的 NgForm

当我尝试在我的 Angular 6 应用程序中的 formGroup 上使用 disable 方法时,我在浏览器控制台中收到此错误:

类型错误:this.personForm.disable 不是函数

尽管文档中提到了该方法,并且VS Code 甚至在此快照中建议了该方法。甚至 VS Code 也建议使用该方法

我的代码在这里:

// ... many parts skipped, the form here is template driven 
// but still personForm is a FormGroup , 
// I am trying to disable the whole FormGroup with all child elements
@ViewChild('personForm') personForm: FormGroup;

        if (true) {
       // if I console.log here the form, I can see it is created already
         console.log(this.personForm);              
// output of console.log is 
// NgForm {submitted: false, …
Run Code Online (Sandbox Code Playgroud)

typescript angular angular-forms angular6

4
推荐指数
1
解决办法
3883
查看次数