【发布时间】:2019-08-23 22:17:58
【问题描述】:
我正在尝试在app.component.html 中设置app.component.ts 中的标签样式,但它不起作用。有类似的问题和文章,但即使是接受的答案也不适合我。这是我的代码。
app.component.html
<div class="container">
<div class="row pt-5">
<div class="col-md-12 col-lg-12 col-sm-12 bg-light">
<form [formGroup]="editorForm" (ngSubmit)="onSubmit()">
<div class="form-group">
<label for="editor">
<h3>Editor</h3>
</label>
<quill-editor [style]="editorStyle" [modules]="config" formControlName="editor"></quill-editor>
</div>
<button class="btn btn-primary mt-3">Submit</button>
</form>
</div>
</div>
</div>
我的app.component.ts 是
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormControl } from '@angular/forms';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
editorForm: FormGroup;
editorStyle = {
height: '300px',
backgroundColor: '#ffffff'
}
config = {
toolbar: [
['bold', 'italic', 'underline'],
['code-block']
]
}
ngOnInit() {
this.editorForm = new FormGroup({
'editor': new FormControl(null)
})
}
onSubmit() {
console.log('submit called');
console.log(this.editorForm.get('editor').value);
}
}
我尝试过的事情:
[style]="editorStyle" //不工作
然后我尝试直接在[style.backgroundColor]="'red'" 使用和不使用额外引号围绕值[style.backgroundColor]='red'。
我也试过[ngStyle]="{backgroundColor: 'red'}" 和[ngStyle.backgroundColor]="'red'"'。但没有什么对我有用。问题仅在于editorStyle 而不是config。我也收到此警告。
警告:清理不安全的样式值 [object Object](请参阅 http://g.co/ng/security#xss)。
【问题讨论】:
-
quill-editor 组件的代码是什么?如果你有主机绑定,它们可以清除主机上的属性。
标签: angular quill property-binding