0

I have some data which can be string or array. So if it is a string, I want to display it, and if it is an array, I want to display length of it.

This how data look like: enter image description here or enter image description here

Trying to check data type of:

<div class="properties">{{typeof(row.contact)=="object" ? 1 : 2}}</div>//with 1 and 2 its more simplify.

But in both cases it will display 2. Why is it so and how can I fixed it?

P.S.

 {{angular.isArray(value)? 1 : 2}}//result the same
4
  • 1
    Possible duplicate of Angular expression to check if model is array or object Commented Jun 22, 2017 at 13:45
  • @PabloMatiasGomez Trying to use angular.isArray but result is the same as I write Commented Jun 22, 2017 at 13:48
  • Strings and Arrays in JavaScript are technically an object. You probably want to check if it is an instanceof a String or Array Commented Jun 22, 2017 at 13:58
  • @Hoyen yes, but operator typeof may return "string" or "object" Commented Jun 22, 2017 at 14:08

1 Answer 1

0

Try define in controller

 $scope.isArray = angular.isArray;

then use

  {{isArray(value)? 1 : 2}}//result the same
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.