我有一个包含 ngx-quill 组件的通用组件。我想调用其他几个组件来获取编辑器而不是输入字段。我成功地完成了这项工作。但是我使用 ngModels 做双向数据绑定,不能在 Div 上使用。如何在我的通用组件中访问它们。
所以这是我的常见组件:
common_component.html
<quill-editor>
</quill-editor>
Common_component.ts:
import { Component } from '@angular/core';
import * as _ from 'underscore';
@Component({
selector: 'app-quill-editor',
templateUrl: './common_component.html'
})
export class CommanQuillComponent {
constructor(
) {}
}
这就是我所说的:
main_component.html
<div>
<app-quill-editor
id="float-input"
placeholder=" "
name="myRange"
step="1"
[(ngModel)]="myVar"
></app-quill-editor>
</div>
main_component.ts 只包含变量声明。
现在的问题是 ngModel 不能在 div 上使用(它会抛出错误),html 认为是 div 标签,然后在其中调用,我想要那个 ngModel on ,我不能手动放置它,因为它将被使用作为通用组件。
请帮助我了解如何实现此数据绑定?
感谢您的支持,如果应该在帖子中添加更易于理解的代码,请告诉我。