Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/28.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.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 如何在ControlValueAccessor组件中包装ngx编辑器_Angular_Controlvalueaccessor_Ngx Monaco Editor - Fatal编程技术网

Angular 如何在ControlValueAccessor组件中包装ngx编辑器

Angular 如何在ControlValueAccessor组件中包装ngx编辑器,angular,controlvalueaccessor,ngx-monaco-editor,Angular,Controlvalueaccessor,Ngx Monaco Editor,我试图使用一个简单的faas应用程序,并试图使它能够在FormGroup中使用 这就是我的组件的外观: @组件({ 选择器:“应用程序编辑器包装器”, 模板:``, 样式URL:['./编辑器包装器.component.scss'], 供应商:[ { 提供:NG_值访问器, useExisting:forwardRef(()=>EditorWrapperComponent), 多:真的 } ] }) 导出类EditorWrapperComponent在ViewInit之后实现ControlVal

我试图使用一个简单的faas应用程序,并试图使它能够在FormGroup中使用

这就是我的组件的外观:

@组件({
选择器:“应用程序编辑器包装器”,
模板:``,
样式URL:['./编辑器包装器.component.scss'],
供应商:[
{
提供:NG_值访问器,
useExisting:forwardRef(()=>EditorWrapperComponent),
多:真的
}
]
})
导出类EditorWrapperComponent在ViewInit之后实现ControlValueAccessor{
@ViewChild(EditorComponent)EditorComponent:EditorComponent;
编辑选项:任何;
值:字符串;
禁用:布尔值;
构造函数(){}
ngAfterViewInit():void{
console.log(this.editorComponent);
}
//#区域控制值存取器
writeValue(对象:任意):无效{
该值=obj;
//此.editor组件未定义
this.editorComponent.writeValue(obj);
}
onChange:()=>{};
注册变更(fn:任何):无效{
this.onChange=fn;
//此.editor组件未定义
此.editorComponent.registerChange(fn);
}
onTouched:()=>{};
注册人(fn:任何):无效{
this.ontoched=fn;
//此.editor组件未定义
this.editorComponent.registeron(fn);
}
setDisabledState?(isDisabled:boolean):无效{
this.disabled=isDisabled;
}
//#端区
ngAfterViewInit():void{
//这个很好用
console.log(this.editorComponent);
}
}
我收到以下错误:


我正在尝试这样做,这样我就可以在表单中使用EditorWrapperComponent,并将formControlName附加到表单中,但无法找到解决方法。如果这不是在表单中使用ngx monaco editor的正确方法,我会接受建议。

我想我已经找到了答案。似乎所有需要做的都是

ngAfterViewInit():void{
this.editorComponent.registerChange(this.onChange);
this.editorComponent.registerOnTouched(this.onTouched);
}

this.onChange和this.onTouched是存储ControlValueAccessor提供的onTouched和onChange函数的变量。

是否需要this.editorComponent.writeValue调用。。?我希望设置这个。值应该足够了。问题是,当writeValue为空时,这个.editorComponent不存在called@MikeOne是的,删除这些调用确实会消除异常。当我以编程方式更改它时,我确实在编辑器中看到了值,例如,new FormControl(“占位符”),但如果我在浏览器中更改它,那么我就看不到FormControl.value的新值。您是否有可能发布整个组件的工作示例?