我有一个控制器:
angular.module('mean').controller('LocationController', [
'$scope', '$location', '$rootScope', '$aside', '$routeParams', '$filter',
'ngTableParams', 'LocationService', 'UserService', 'CompanyService',
function ($scope, $location, $rootScope, $aside, $routeParams, $filter,
ngTableParams, LocationService, UserService, CompanyService) {
$rootScope.menuItem = 'locations';
$scope.contentTemplate = '/views/location/index.html';
$scope.locations = [];
$scope.current_location = null;
$scope.newLocation = {};
$scope.location_parent_id = $routeParams.location_parent_id;
$scope.validation_errors = [];
$scope.index = function() {
CompanyService.initialized.then(function() {
var company_id = CompanyService.getCompany()._id;
LocationService.list(company_id, $routeParams.location_parent_id).then(function(response) {
if(response.data.status === 'ok') {
$scope.locations = response.data.locations;
$scope.current_location = response.data.location || null;
} else {
alert('TBD');
}
});
});
$scope.tableParams = new ngTableParams({
page: 1,
count: 10,
}, {
total: $scope.locations.length,
getData: function($defer, params) {
var orderedData = params.sorting() ? $filter('orderBy')($scope.locations, params.orderBy()) : $scope.locations;
orderedData = params.filter() ? $filter('filter')(orderedData, params.filter()) : orderedData;
$scope.locations = orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count());
params.total(orderedData.length);
$defer.resolve($scope.locations);
}
});
}
$scope.addLocationModal = function() {
$scope.location_types = ['warehouse', 'section', 'row', 'shelf', 'bin'];
$aside({
scope: $scope,
template: '/views/location/addLocationAside.html',
show: true
});
}
$scope.createLocation = function() {
$scope.newLocation.company_id = CompanyService.getCompany()._id;
LocationService.create($scope.newLocation).then(function(response) {
if(response.data.status === 'ok') {
$scope.$hide();
$scope.index();
} else {
$scope.validation_errors = response.data.error;
}
});
}
}
]);
在模态中,我有一个表单,提交时调用createLocation
函数。如果位置创建成功,我希望关闭模式并运行索引并重新更新列表。但这似乎并没有发生。我认为这是一个$scope
问题,但我不确定是什么。