1

say I have an angular expression like this:

<span>{{vm.name}} {{vm.property|prettyPrint}}</span>

Say that property is optional, and may result in empty string. How do I get rid of that no-longer-necessary space after the name? I tried doing something like

<span>{{vm.name + ' ' + vm.property|prettyPrint |trim}}</span>

but that doesn't work.

2 Answers 2

2

The reason

<span>{{vm.name + ' ' + vm.property|prettyPrint |trim}}</span> 

doesn't work is because it's applying the prettyPrint filter to everything. Change it to this:

<span>{{ (vm.name + ' ' + (vm.property | prettyPrint)) | trim }}</span>
Sign up to request clarification or add additional context in comments.

1 Comment

I really should stop working so late - I come up with the most complicated solutions to the simplest of problems. Thanks
0

Place the space inside the propery like this

<span>{{vm.name}}{{' ' + vm.property|prettyPrint}}</span>

1 Comment

i thought you said the the vm.property might be optional, rephrase your question please :)

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.