Angular 2 contenteditable

后端 未结 7 1445
野的像风
野的像风 2020-12-15 05:07

In Angular 2 how can I make two way data binding with a contenteditable div?

Text Field

7条回答
  •  再見小時候
    2020-12-15 05:48

    Angular 4/2 (Typescript) with dynamic editable:

    // Imports
    import { Component} from '@angular/core';
    
    @Component({
        selector: 'discussion',
        template: `                                 
        

    Wednesday 14 Nov, 2016 10.13PM

    {{ discussion }}

    `, styles: [`.editable { white-space: pre-wrap; border: 1px solid coral; width: 200px; min-height: 20px; }`] }) export class DiscussionComponent { constructor(){} public discussion: string = "Test string"; public editable: boolean = false; dDiscussion(){ console.log("delete"); } eDiscussion(event: any){ // on click this will set 'contentEditable' to true // and add 'editable' class for styling. this.editable = true; } uDiscussion(event: any){ // on blur set 'contentEditable' to false // and remove class 'editable' and log new values this.editable = false; console.log("this.discussion"); console.log(this.discussion); } }

提交回复
热议问题