Placeholder text using ngModelController?

314 views
Skip to first unread message

Anuj

unread,
Oct 17, 2012, 12:38:35 AM10/17/12
to ang...@googlegroups.com
I wanted to add placeholder text in a contenteditable div using the ngModelController.  The requirement is that placeholder text appear every time there is no value in the div.  I am unable to get it to work properly.  

Failure points:
  1. If I type something in the div and then delete it, the html of the element shows <br>.  If I use .text instead, it ignores new line characters.  Hence, I don't always get the placeholder text.  This is not an angularJS relevant issue, but I would appreciate help.
  2. If I clear out the model, the user entered text remains in the div, but my logic also causes the placeholder to appear.

Can someone recommend a better approach to doing this.

Thanks,

Anuj


Simon Bernard

unread,
Jan 29, 2014, 11:13:36 AM1/29/14
to ang...@googlegroups.com

I did it like this:

In the css:
[placeholder-text]:not(:focus):empty:before {
    content: attr(placeholder-text);
    float: left;
    margin-left: 2px;
    color: rgba(200,200,200,1);
}

the element looks like this:
<div contenteditable=true placeholder-text="Description"></div>

it works fine!
Reply all
Reply to author
Forward
0 new messages