1

レールでAngularモジュールng-table(http://ngmodules.org/modules/ng-table)を使用しています-Angularアプリ。問題は、ng-table が URL のパスの一部を複製していることです。

EG: URL は である必要があります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. Angular コントローラーがビューにデータを入力します

結論:ルーティングに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'
});

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

0 に答える 0