:host() ::ng-deep .CodeMirror{
height:250px
}
您只需将组件添加到包装器/容器元素中即可。
<div class="container">
<ngx-codemirror
[(ngModel)]="sql_input"
[options]="{ lineNumbers: true, theme: 'material', mode: 'markdown' }"
></ngx-codemirror>
</div>
然后将所需的宽度和高度设置为容器。
.container {
width: 500px;
height: 500px;
}
import { Component, OnInit, ViewChild, ViewEncapsulation } from '@angular/core';
@Component({
selector: 'app-my-component',
templateUrl: './my.component.html',
styleUrls: ['./my.component.scss'],
encapsulation: ViewEncapsulation.None,
})
export class MyComponent implements OnInit {
@ViewChild('CodeMirror') private cm: any;
codemirrorOptions = {
lineNumbers: false,
lineWrapping: true,
viewportMargin: Infinity,
};
...
my.component.html:
<ngx-codemirror
#CodeMirror
[(ngModel)]="myModel"
(ngModelChange)="onChanged($event)"
[options]="codemirrorOptions"
ngDefaultControl
></ngx-codemirror>
my.component.scss:
.CodeMirror {
height: auto;
}