0

I have snippet of a view. vm.items is an object, each item of object contains an email or phone and the code correspondingly. For example {value:'123456', code: 'phone'}.

.contacts
    .contact(ng-repeat='item in vm.items track by $index')
      span {{item | phone}}

The question is how could i apply filter only when item is a phone. It means the code of item is phone, and when it is an email leave it as is. I thought i could use ternary operator and have something like this: span {{item | item.code === "phone"? phone : '' }}, but i didn't succeed. I cannot change the phone filter code and pass any parameters to this filter. I cannot create new filter for email.

3
  • what was the error when you tried span {{item | item.code === "phone"? phone : '' }} ? Commented Nov 14, 2017 at 12:01
  • I got a syntax error angular.js:14700 Error: [$parse:syntax] Syntax Error: Token '.' is an unexpected token at column 12 of the expression [item | item.code === "phone"? phone : ''] starting at [.code === "phone"? phone : '']. Commented Nov 14, 2017 at 12:10
  • 2
    try {{ item.code === "phone" ? (item | phone) : item }} Commented Nov 14, 2017 at 12:14

1 Answer 1

2

I would do following:

{{ item.code === "phone" ? (item | phone) : item }}
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.