Angular模块ng-table正在复制URL中路径的一部分

时间:2013-09-16 06:01:56

标签: javascript ruby-on-rails angularjs

我在我的rails - angular应用程序中使用角度模块ng-table(http://ngmodules.org/modules/ng-table)。问题是,ng-table正在复制我网址中路径的一部分。

E.G。:网址应为http://host.com/hostings/1/email-accounts,但在模块中的某处,它会变为http://host.com/hostings/1/email-accounts#/email-accounts

我的申请按以下方式运作:

  1. 用户访问http://host.com/hostings/1/email-accounts
  2. Rails使用ng-controller指令和一些基本布局(在本例中为ng-controller =“EmailAccountsCtrl”)呈现视图
  3. 角度控制器填充视图
  4. 底线:我没有使用角度来进行路由。

    这是我的角度配置

    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'
    });
    

    EmailAccountsCtrl

    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
            });
          };          
        }
      ],
    

0 个答案:

没有答案