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
kliukovking
  • 569
  • 1
  • 5
  • 16
  • 1
    Possible duplicate of [Angular expression to check if model is array or object](https://stackoverflow.com/questions/22356582/angular-expression-to-check-if-model-is-array-or-object) – Pablo Matias Gomez Jun 22 '17 at 13:45
  • @PabloMatiasGomez Trying to use angular.isArray but result is the same as I write – kliukovking Jun 22 '17 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` – Hoyen Jun 22 '17 at 13:58
  • @Hoyen yes, but operator typeof may return "string" or "object" – kliukovking Jun 22 '17 at 14:08

1 Answers1

0

Try define in controller

 $scope.isArray = angular.isArray;

then use

  {{isArray(value)? 1 : 2}}//result the same
Hadi J
  • 16,989
  • 4
  • 36
  • 62