2017-06-22 30 views
0

我有一些數據可以是字符串或數組。所以如果它是一個字符串,我想顯示它,如果它是一個數組,我想顯示它的長度。Angularjs檢查數組的類型

這個數據看起來怎麼樣: enter image description hereenter image description here

嘗試檢查的數據類型:

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

但在這兩種情況下,它會顯示2。爲什麼會這樣,我該如何修復它?

P.S.

{{angular.isArray(value)? 1 : 2}}//result the same 
+1

的可能的複製[角表達,以檢查是否模型是數組或對象(https://stackoverflow.com/問題/ 22356582/angular-expression-to-check-if-model-is-array-or-object) –

+0

@PabloMatiasGomez嘗試使用angular.isArray,但結果與我寫的相同 – RoGGeR

+0

JavaScript中的字符串和數組是t一個物體。你可能想檢查它是''instanceof'' String還是'Array' – Hoyen

回答

0

嘗試限定在控制器

$scope.isArray = angular.isArray; 

然後使用

{{isArray(value)? 1 : 2}}//result the same