我想在URL中查詢字符串的值上運行angular.forEach函數。Angular for each function troublebles
考慮以下幾點:
domain.com?quote=10"e=20
否則$scope.selectedQuotes = $stateParams.quote;
按預期方式工作,並輸出["10", "20"]
,創建一個數組。
但具有相同功能的上:
domain.com?quote=10
此輸出「10」作爲一個字符串,並運行在foreach上每個字符。
下面是完整的代碼:
$scope.selectedQuotes = $stateParams.quote;
console.log($scope.selectedQuotes);
angular.forEach($scope.selectedQuotes, function(quote){
}
所以現在的問題是,你如何獲得它,所以它總是類值作爲一個數組?
這似乎是預期的行爲給我。你必須檢測它是一個數組還是一個字符串,並相應地採取行動。 –
@KevinB文檔已經陳述相同..我已經添加它作爲答案 –