我有一个简单的角度2组件:
Run Code Online (Sandbox Code Playgroud)@Component({ selector: 'test-text', template: `<p> Text </p>` }) export class TestComponent { constructor() {} getHtmlContent() {return;} //This should return '<p> Text </p>' as a string }
我可以将组件的html内容最简单的方法用于什么?
我有以下代码:
<div #test (click)="onClick(test)" contenteditable="true">
This text can be edited by the user.
</div>
@ViewChild('test') el:ElementRef;
constructor(private elementRef: ElementRef) {}
onClick(event) {
console.log(this.el.nativeElement);
let cursor = this.el.nativeElement.selectionStart; //gives undefined
}
Run Code Online (Sandbox Code Playgroud)
当用户单击文本时,如何获取“ div”元素的光标位置?