2

I have a bizarre issue with the following code:

I save text that has been inputted using a areatext-box to a SQL DB. In the DB there are no leading or trailing white spaces.

When I then display the text inside a div using angular {{ model.text }}

it magically adds these weird leading and trailing white spaces:

<pre class="ng-binding">        Line1
Line2
Line3
Line4                            
    </pre>

as you can see in the pre tag there is leading and trailing spaces. Please note that this also happens when this is inside a div and is not restricted to the pre tags.

I am stumped..

I already tried a filter to remove leading and trailing spaces and also nuked all css on the parent containers.

4
  • Are there those white spaces in the Ajax Response? Commented Dec 19, 2014 at 9:40
  • None at all in the ajax payload. Commented Dec 19, 2014 at 10:46
  • Have you tried using :<pre ng-trim="true"> ? Commented Dec 19, 2014 at 13:48
  • this might come from your original, unrendered code, try removing all the whitespace there Commented Dec 19, 2014 at 14:26

1 Answer 1

9

I know this is an old question but I recently had the same issue and it was due to my use of line breaks and indents inside the <pre> tags. For instance, my original code looked like:

<pre>
    {{model.text}}
</pre>

This gave the results you described. My solution was to remove the line breaks and indents so that it was all on one line:

<pre>{{model.text}}</pre>

Doing so fixed the issue for me.

I understand your experience isn't limited to <pre> tags, but unfortunately, I don't have a good explanation for that. Just wanted to add an answer in case it helps someone down the road.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for sharing Ian :-) It might be old today but tomorrow this might be new to someone else:)
Thanks, had the same ridiculous issue. I'm suck a good developer. Edit: lol, I suck too

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.