我有一個簡單的角度函數,我調用一個服務來獲取數據並將它作爲JS數組存儲爲一個角度範圍。問題是範圍對象中的數組在我的HTML中不可見。這裏有一件事是我將我的視圖重定向到另一個HTML,我不確定這是否是一個原因。Angular Scope對象不保留值並在HTML中返回null
cart.items(localStorage.getItem('userEmail')).then(function(response){
$.each(response.data, function(index, element) {
$scope.vendorCartList.push(element);
});
$location.path('/vendorHome');
})
當我在調試控制檯中轉儲這個範圍數組$ scope.vendorCartList時,它會正確顯示內容。 在我的HTML vendorHome.html中,我試圖通過ng-repeat檢索列表,並且它永遠不會工作。我試圖轉儲範圍對象,其打印null,不知道我在這裏丟失什麼
<div>
{{vendorCartList}}
</div>
<div ng-repeat="elements in vendorCartList">
{{elements}}
</div>
謝謝,這對我很有用。我在vendorController中注入了服務並調用了該函數,然後我可以在HTML – CrazyMac
中獲取此列表,我很高興能夠提供幫助。 :) – sisyphus