1

I want to escape the single quotes in the unique filter in angular but I can't, I've tried it in the following ways. If the field wouldn't have a hyphen I could do attrbutes.displayname and it will work (I've tried it), but I have a hyphen...

Example:

<select ng-model="style" ng-options="block.attributes['display-name'] for (blockName, block) in styleBlocks | unique:'attributes[\'display-name\']'">

<select ng-model="style" ng-options="block.attributes['display-name'] for (blockName, block) in styleBlocks | unique:'attributes[\\'display-name\\']'">
3
  • 4
    why you don't create a function in your controller or create a custom filter for this complex queries, it would be cleaner. Don't you think? Commented Sep 2, 2014 at 15:41
  • Thanks for the idea, I prefer to use standard and well-tested functionalities. Commented Sep 2, 2014 at 16:07
  • 1
    A $filter, as @Dalorzo suggests, is in fact the standard and well-tested (and maintainable, and readable, and....) way to do anything other than the most basic filtering. Commented Jul 9, 2015 at 17:43

1 Answer 1

1

Use the Unicode escape \u0027 for single quotes:

'attributes[\u0027display-name\u0027]'

References

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

Comments

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.