我目前正在填充$scope
陣列像最簡單的方法:
$scope.categories = [];
$scope.getCategories = function() {
ItemService.getCategories().success(function(categories) {
$scope.categories = categories;
});
}
$scope.getCategories();
這真的是做到這一點的最簡單的方法?
難的部分在哪裏? –
這並不難,只是很多代碼 – Pixark
爲什麼將服務調用包裝在範圍函數中?除非您的界面通過某些事件觸發它,否則不需要。另外,如果你想在控制器初始化時加載類別,你應該看看在路由的解析函數中執行它,或者如果你不使用路由,那麼在應用程序的運行函數中。 –