我正在使用一个静态json文件来模拟我的服务器并从中获取我的一系列命令。 我在我的html文件中的表格中显示订单,并从中删除一个订单。 每次我加载html文件时,完整列表都会被加载,并且我已经通过控制器功能删除了这些命令。Angular JS:我怎样才能加载工厂一次?
我怎样才能从工厂只有一次数据?
这里是我的控制器:
app.controller("MainPageCtrl", function($scope, getOrdersFactory)
{
$scope.orders = [];
// Getting the data frm the facrory
var dataPromise = getOrdersFactory.getDataFunc();
dataPromise.then(function(data){
$scope.orders = data.orders;
});
// Deletes an orders.
$scope.deleteOrder = function(order){
// Finds the index of the order.
var orderIndex = $scope.orders.indexOf(order);
// Delete the order.
$scope.orders.splice(orderIndex, 1);
};
});
你到底是什么意思?一旦进入......什么?你想在浏览器缓存中存储一些数据吗? – k102
请参阅http://stackoverflow.com/questions/22182730/angularjs-service-only-running-the-first-time-controller-is-used。 – Ioan