0
我有一些數據可以是字符串或數組。所以如果它是一個字符串,我想顯示它,如果它是一個數組,我想顯示它的長度。Angularjs檢查數組的類型
嘗試檢查的數據類型:
<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
的可能的複製[角表達,以檢查是否模型是數組或對象(https://stackoverflow.com/問題/ 22356582/angular-expression-to-check-if-model-is-array-or-object) –
@PabloMatiasGomez嘗試使用angular.isArray,但結果與我寫的相同 – RoGGeR
JavaScript中的字符串和數組是t一個物體。你可能想檢查它是''instanceof'' String還是'Array' – Hoyen