Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 在自定义被动表单控件上禁用设置会导致超出最大调用堆栈大小_Angular_Custom Controls_Angular Reactive Forms - Fatal编程技术网

Angular 在自定义被动表单控件上禁用设置会导致超出最大调用堆栈大小

Angular 在自定义被动表单控件上禁用设置会导致超出最大调用堆栈大小,angular,custom-controls,angular-reactive-forms,Angular,Custom Controls,Angular Reactive Forms,我在Angular项目中构建了一个自定义输入控件。这一切都很好,除非我将disabled属性设置为true,然后在setDisabledState上发生无限循环,导致 preview-4adb70f742b91f09679fb.js:1 ERROR RangeError: Maximum call stack size exceeded at eval (model.ts:1519) at eval (model.ts:1531) at eval (model.ts:14

我在Angular项目中构建了一个自定义输入控件。这一切都很好,除非我将disabled属性设置为true,然后在setDisabledState上发生无限循环,导致

preview-4adb70f742b91f09679fb.js:1 ERROR RangeError: Maximum call stack size exceeded
    at eval (model.ts:1519)
    at eval (model.ts:1531)
    at eval (model.ts:1493)
    at Array.forEach (<anonymous>)
    at FormGroup._forEachChild (model.ts:1493)
    at FormGroup._reduceChildren (model.ts:1530)
    at FormGroup._reduceValue (model.ts:1518)
    at FormGroup._updateValue (model.ts:1505)
    at FormGroup.AbstractControl.updateValueAndValidity (model.ts:575)
    at FormControl.AbstractControl._updateAncestors (model.ts:533)
preview-4adb70f742b91f09679fb.js:1错误范围错误:超过最大调用堆栈大小
评估时(型号ts:1519)
评估时(型号ts:1531)
评估时(型号ts:1493)
在Array.forEach(

关于设置内部FormControl的disabled属性(使用diabled(),enabled()),我是否遗漏了一些内容


如果是这样的话,请让我知道如何解决这个问题。在代码中,您可以通过根据布尔值setDisabledState()参数设置禁用状态来强制循环。在这个方法中,您可以调用disable()/enable(),这将调用setDisabledState()本身

  setDisabledState?(isDisabled: boolean): void {
    isDisabled ? this.control.disable() : this.control.enable();
  }

尝试一下Netnel Basal的做法:

  setDisabledState( isDisabled : boolean ) : void {
    const div = this.textarea.nativeElement;
    const action = isDisabled ? 'addClass' : 'removeClass';
    this.renderer[action](div, 'disabled');
  }

谢谢,我想我现在解决了。我也看了。更新的stackblitz现在没有显示任何错误。