Strange behavior on editable div when trying to update a variable with text content in an editable div in angular. Any explanations? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceHow to use [(ngModel)] on div's contenteditable in angular2?Force contenteditable div to stop accepting input after it loses focus under WebkitPrevent contenteditable element from getting focus when clicking parentCannot display HTML stringPaste Event on html div without content editableAngular 2 JIT Compiler very strange behaviorkeyboard events binding in component within contenteditableAngular 4 update input text value via Host listenerNew Line not working properly in Angular 2 editable divCursor position lost when updating contenteditable div in Elmreact div content editable render value with span

What's the point in a preamp?

Estimate capacitor parameters

What are the performance impacts of 'functional' Rust?

Is above average number of years spent on PhD considered a red flag in future academia or industry positions?

Estimated State payment too big --> money back; + 2018 Tax Reform

What is the electric potential inside a point charge?

Simulating Exploding Dice

How does modal jazz use chord progressions?

Losing the Initialization Vector in Cipher Block Chaining

Would an alien lifeform be able to achieve space travel if lacking in vision?

How is simplicity better than precision and clarity in prose?

Statistical model of ligand substitution

Why does this iterative way of solving of equation work?

How many spell slots should a Fighter 11/Ranger 9 have?

How can I make names more distinctive without making them longer?

Notation for two qubit composite product state

Can I throw a sword that doesn't have the Thrown property at someone?

Classification of bundles, Postnikov towers, obstruction theory, local coefficients

Complexity of many constant time steps with occasional logarithmic steps

When is phishing education going too far?

Is there folklore associating late breastfeeding with low intelligence and/or gullibility?

Does a C shift expression have unsigned type? Why would Splint warn about a right-shift?

What do you call a plan that's an alternative plan in case your initial plan fails?

Can a 1st-level character have an ability score above 18?



Strange behavior on editable div when trying to update a variable with text content in an editable div in angular. Any explanations?



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
The Ask Question Wizard is Live!
Data science time! April 2019 and salary with experienceHow to use [(ngModel)] on div's contenteditable in angular2?Force contenteditable div to stop accepting input after it loses focus under WebkitPrevent contenteditable element from getting focus when clicking parentCannot display HTML stringPaste Event on html div without content editableAngular 2 JIT Compiler very strange behaviorkeyboard events binding in component within contenteditableAngular 4 update input text value via Host listenerNew Line not working properly in Angular 2 editable divCursor position lost when updating contenteditable div in Elmreact div content editable render value with span



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















I am trying to create a text editor and have created a custom element in angular using an editable div.



I will have to set some initial value to the content of the div in some cases and capture the typed data in the div in some cases.



But I am getting three different behaviors for the same div based on the initial value that is set.



I want the div to behave like a regular input field but I don't want to use the actual Input element.



I have made a working example of the problem in the Stackblitz demo.



The components code is as below.



The template HTML for the element component:



<div contentEditable='true' (input)="update($event)">value</div>
<p>value</p>


The typescript file for the component element:



import Component, Input from '@angular/core';

@Component(
selector: 'element',
template: `<div contentEditable='true' (input)="update($event)">value</div>
<p>value</p>
`,
styleUrls: ['./element.component.css']
)
export class ElementComponent
@Input() value: string;

update(event)
this.value = event.target.innerText;




The CSS:



div
background: black;
margin: auto;
color:white;
font-size: 2em;



The three different behaviors are:



  1. If you do not set an initial value to the value input field, as you
    type in the div, the text gets appended to itself continuously.

  2. If you provide an initial value to the value input field, as you type
    in the div, the cursor resets it to the initial position.

  3. Whether you provide an initial text or you type something in the empty div, If you select all the text from the div and hit delete or backspace
    and start typing in it. It behaves as a normal textbox.

I am expecting the 3rd behavior, in example after you clear the element the way it behaves.










share|improve this question






























    1















    I am trying to create a text editor and have created a custom element in angular using an editable div.



    I will have to set some initial value to the content of the div in some cases and capture the typed data in the div in some cases.



    But I am getting three different behaviors for the same div based on the initial value that is set.



    I want the div to behave like a regular input field but I don't want to use the actual Input element.



    I have made a working example of the problem in the Stackblitz demo.



    The components code is as below.



    The template HTML for the element component:



    <div contentEditable='true' (input)="update($event)">value</div>
    <p>value</p>


    The typescript file for the component element:



    import Component, Input from '@angular/core';

    @Component(
    selector: 'element',
    template: `<div contentEditable='true' (input)="update($event)">value</div>
    <p>value</p>
    `,
    styleUrls: ['./element.component.css']
    )
    export class ElementComponent
    @Input() value: string;

    update(event)
    this.value = event.target.innerText;




    The CSS:



    div
    background: black;
    margin: auto;
    color:white;
    font-size: 2em;



    The three different behaviors are:



    1. If you do not set an initial value to the value input field, as you
      type in the div, the text gets appended to itself continuously.

    2. If you provide an initial value to the value input field, as you type
      in the div, the cursor resets it to the initial position.

    3. Whether you provide an initial text or you type something in the empty div, If you select all the text from the div and hit delete or backspace
      and start typing in it. It behaves as a normal textbox.

    I am expecting the 3rd behavior, in example after you clear the element the way it behaves.










    share|improve this question


























      1












      1








      1








      I am trying to create a text editor and have created a custom element in angular using an editable div.



      I will have to set some initial value to the content of the div in some cases and capture the typed data in the div in some cases.



      But I am getting three different behaviors for the same div based on the initial value that is set.



      I want the div to behave like a regular input field but I don't want to use the actual Input element.



      I have made a working example of the problem in the Stackblitz demo.



      The components code is as below.



      The template HTML for the element component:



      <div contentEditable='true' (input)="update($event)">value</div>
      <p>value</p>


      The typescript file for the component element:



      import Component, Input from '@angular/core';

      @Component(
      selector: 'element',
      template: `<div contentEditable='true' (input)="update($event)">value</div>
      <p>value</p>
      `,
      styleUrls: ['./element.component.css']
      )
      export class ElementComponent
      @Input() value: string;

      update(event)
      this.value = event.target.innerText;




      The CSS:



      div
      background: black;
      margin: auto;
      color:white;
      font-size: 2em;



      The three different behaviors are:



      1. If you do not set an initial value to the value input field, as you
        type in the div, the text gets appended to itself continuously.

      2. If you provide an initial value to the value input field, as you type
        in the div, the cursor resets it to the initial position.

      3. Whether you provide an initial text or you type something in the empty div, If you select all the text from the div and hit delete or backspace
        and start typing in it. It behaves as a normal textbox.

      I am expecting the 3rd behavior, in example after you clear the element the way it behaves.










      share|improve this question
















      I am trying to create a text editor and have created a custom element in angular using an editable div.



      I will have to set some initial value to the content of the div in some cases and capture the typed data in the div in some cases.



      But I am getting three different behaviors for the same div based on the initial value that is set.



      I want the div to behave like a regular input field but I don't want to use the actual Input element.



      I have made a working example of the problem in the Stackblitz demo.



      The components code is as below.



      The template HTML for the element component:



      <div contentEditable='true' (input)="update($event)">value</div>
      <p>value</p>


      The typescript file for the component element:



      import Component, Input from '@angular/core';

      @Component(
      selector: 'element',
      template: `<div contentEditable='true' (input)="update($event)">value</div>
      <p>value</p>
      `,
      styleUrls: ['./element.component.css']
      )
      export class ElementComponent
      @Input() value: string;

      update(event)
      this.value = event.target.innerText;




      The CSS:



      div
      background: black;
      margin: auto;
      color:white;
      font-size: 2em;



      The three different behaviors are:



      1. If you do not set an initial value to the value input field, as you
        type in the div, the text gets appended to itself continuously.

      2. If you provide an initial value to the value input field, as you type
        in the div, the cursor resets it to the initial position.

      3. Whether you provide an initial text or you type something in the empty div, If you select all the text from the div and hit delete or backspace
        and start typing in it. It behaves as a normal textbox.

      I am expecting the 3rd behavior, in example after you clear the element the way it behaves.







      html css angular contenteditable






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 22 at 9:02









      Mukyuu

      2,12131125




      2,12131125










      asked Mar 22 at 7:06









      Rahul kalivaradarajaluRahul kalivaradarajalu

      467




      467






















          1 Answer
          1






          active

          oldest

          votes


















          1














          Possible explanation: You haven't declared the bound value.



          Workaround:
          Adding:



          [textContent]="model" when declaring template div



           model;
          ngOnInit()
          this.model = this.value;



          inside ElementComponent export class



          Stackblitz Demo



          Related:
          How to use [(ngModel)] on div's contenteditable in angular2?,
          https://github.com/KostyaTretyak/ng-stack/tree/master/projects/contenteditable






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55294502%2fstrange-behavior-on-editable-div-when-trying-to-update-a-variable-with-text-cont%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            Possible explanation: You haven't declared the bound value.



            Workaround:
            Adding:



            [textContent]="model" when declaring template div



             model;
            ngOnInit()
            this.model = this.value;



            inside ElementComponent export class



            Stackblitz Demo



            Related:
            How to use [(ngModel)] on div's contenteditable in angular2?,
            https://github.com/KostyaTretyak/ng-stack/tree/master/projects/contenteditable






            share|improve this answer



























              1














              Possible explanation: You haven't declared the bound value.



              Workaround:
              Adding:



              [textContent]="model" when declaring template div



               model;
              ngOnInit()
              this.model = this.value;



              inside ElementComponent export class



              Stackblitz Demo



              Related:
              How to use [(ngModel)] on div's contenteditable in angular2?,
              https://github.com/KostyaTretyak/ng-stack/tree/master/projects/contenteditable






              share|improve this answer

























                1












                1








                1







                Possible explanation: You haven't declared the bound value.



                Workaround:
                Adding:



                [textContent]="model" when declaring template div



                 model;
                ngOnInit()
                this.model = this.value;



                inside ElementComponent export class



                Stackblitz Demo



                Related:
                How to use [(ngModel)] on div's contenteditable in angular2?,
                https://github.com/KostyaTretyak/ng-stack/tree/master/projects/contenteditable






                share|improve this answer













                Possible explanation: You haven't declared the bound value.



                Workaround:
                Adding:



                [textContent]="model" when declaring template div



                 model;
                ngOnInit()
                this.model = this.value;



                inside ElementComponent export class



                Stackblitz Demo



                Related:
                How to use [(ngModel)] on div's contenteditable in angular2?,
                https://github.com/KostyaTretyak/ng-stack/tree/master/projects/contenteditable







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 22 at 7:38









                MukyuuMukyuu

                2,12131125




                2,12131125





























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55294502%2fstrange-behavior-on-editable-div-when-trying-to-update-a-variable-with-text-cont%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

                    155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해