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;
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:
- 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. - 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. - 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
add a comment |
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:
- 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. - 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. - 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
add a comment |
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:
- 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. - 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. - 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
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:
- 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. - 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. - 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
html css
edited Mar 22 at 9:02
Mukyuu
2,12131125
2,12131125
asked Mar 22 at 7:06
Rahul kalivaradarajaluRahul kalivaradarajalu
467
467
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
add a comment |
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
add a comment |
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
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
answered Mar 22 at 7:38
MukyuuMukyuu
2,12131125
2,12131125
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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