我在我的 rails - angular 应用程序中使用了角度模块 ng-table ( http://ngmodules.org/modules/ng-table )。问题是,ng-table 在我的 URL 中复制了部分路径。
EG:URL 应该http://host.com/hostings/1/email-accounts
在它变成的模块中的某个位置http://host.com/hostings/1/email-accounts#/email-accounts
。
我的应用程序以下列方式工作:
- 用户访问http://host.com/hostings/1/email-accounts
- Rails 使用 ng-controller 指令和一些基本布局呈现视图(在本例中,ng-controller="EmailAccountsCtrl")
- Angular 控制器填充视图
底线:我没有使用角度进行路由。
这是我的角度配置:
admin = angular.module('admin', ['ngResource', 'hostingsModule', 'ui.bootstrap.modal', 'ui.bootstrap.datepicker']);
admin.config(function($locationProvider, $httpProvider) {
$httpProvider.defaults.useXDomain = true;
delete $httpProvider.defaults.headers.common['X-Requested-With'];
$httpProvider.defaults.headers.common['Access-Control-Allow-Origin'] = 'https://sadmin.igloonet.cz'
});
电子邮件帐户控件:
hostingsModule.controller('EmailAccountsCtrl', ['$scope', '$q', '$filter', 'Hosting', 'EmailAccount', 'ngTableParams', function($scope, $q, $filter, Hosting, EmailAccount, ngTableParams) {
var hostingId;
$scope.emailAccounts = [];
$scope.hosting = findHosting(hostingId);
$scope.tableParams = new ngTableParams({
$liveFiltering: true,
page: 1,
total: 0,
count: 10,
sorting: {
email: 'asc'
}
});
$scope.$watch('tableParams', function(params) {
if (angular.equals({},params.filter)) {
$scope.tableParams.disabledButton = true;
} else {
$scope.tableParams.disabledButton = false;
}
$scope.loading = true;
EmailAccount.all(hostingId, params.url()).success(function(data) {
$scope.loading = false;
$scope.emailAccounts = data.emailAccounts;
$scope.tableParams.total = data.total;
});
});
}]);
以及ng-table 指令控制器的一部分:
controller: [
"$scope", "$timeout", function($scope, $timeout) {
var updateParams;
$scope.params = $scope.params || {
page: 1,
count: 10
};
// When I log the url here, it's still correct
$scope.$watch('params.filter', (function(value) {
// When I log the url here, it has the part with #email-accounts already appended
if ($scope.params.$liveFiltering) {
console.log(updateParams());
updateParams(value);
return $scope.goToPage(1);
}
}), true);
updateParams = function(newParams) {
newParams = angular.extend($scope.params, newParams);
$scope.paramsModel.assign($scope.$parent, new ngTableParams(newParams));
return $scope.params = angular.copy(newParams);
};
$scope.goToPage = function(page) {
if (page > 0 && $scope.params.page !== page && $scope.params.count * (page - 1) <= $scope.params.total) {
return updateParams({
page: page
});
}
};
$scope.changeCount = function(count) {
return updateParams({
page: 1,
count: count
});
};
$scope.doFilter = function() {
return updateParams({
page: 1
});
};
return $scope.sortBy = function(column) {
var sorting, sortingParams;
if (!column.sortable) {
return;
}
sorting = $scope.params.sorting && $scope.params.sorting[column.sortable] && ($scope.params.sorting[column.sortable] === "desc");
sortingParams = {};
sortingParams[column.sortable] = (sorting ? "asc" : "desc");
return updateParams({
sorting: sortingParams
});
};
}
],