Angular trimming attribute value

31 views
Skip to first unread message

Miguel Guedes

unread,
Mar 17, 2015, 2:50:43 PM3/17/15
to ang...@googlegroups.com
I have got a directive acting on the document's title that accepts a `prefix´ attribute that is prepended to the actual document title. 

The problem I'm having is that Angular is trimming the contents even though I specifically need it to retain whitespace.  I've tried using the `ng-trim="false"´ directive but still no luck.

The directive is intended to be used as follows:

<title prefix="App - ">Default app title</title>

What can be done to disable trimming?

Sander Elias

unread,
Mar 17, 2015, 11:24:37 PM3/17/15
to ang...@googlegroups.com

Hi Miguel,

Without a plunk I’m not too sure, however, if you really need the exact text from the attribute, you can do something like $element[0].getAttribute('prefix') in your directive and be done with it.

Regards
Sander

Miguel Guedes

unread,
Mar 18, 2015, 3:53:31 PM3/18/15
to ang...@googlegroups.com
On 18/03/15 03:24, Sander Elias wrote:
> Without a plunk I’m not too sure, however, if you really need the exact
> text from the attribute, you can do something like
> |$element[0].getAttribute('prefix')| in your directive and be done with it.

This works nicely, Sander -- thank you! Have to confess, though, that
the purist in me would still like to know the Angular way of achieving
this; plus, it would be a good lesson. Do you have any ideas as to how
it might be possible to instruct Angular to not do the trimming?

Sander Elias

unread,
Mar 18, 2015, 10:31:45 PM3/18/15
to ang...@googlegroups.com
Hi Miguel,

Trimming is being discussed a few times, and there have been changes just for that, I just don't remember what is in which version. If you really want to know, just try a couple of things, build a plunk, just to poke around with the different options. That's what I would do ;) (Oh, and of coarse I would read the angular code..)

Regards
Sander
Reply all
Reply to author
Forward
0 new messages