Javascript 带有特定子状态的ui路由器仅在页面刷新时呈现JSON,无视图

Javascript 带有特定子状态的ui路由器仅在页面刷新时呈现JSON,无视图,javascript,angularjs,angular-ui-router,angular-ui-router-extras,Javascript,Angularjs,Angular Ui Router,Angular Ui Router Extras,我在整个应用程序中都使用了这种架构,但它在这里不起作用,我也不知道为什么 我正在将威士忌数据加载到我的父州威士忌,它应该将数据传递到子州。它工作正常,但在页面刷新时——它只在页面上显示威士忌的json数据 Angular似乎没有加载,因为我的ng inspector工具没有检测到它 //parent state with resolve to retrieve whiskey from service .state('whiskey', { url: '/whiskey/

我在整个应用程序中都使用了这种架构,但它在这里不起作用,我也不知道为什么

我正在将威士忌数据加载到我的父州威士忌,它应该将数据传递到子州。它工作正常,但在页面刷新时——它只在页面上显示威士忌的json数据

Angular似乎没有加载,因为我的ng inspector工具没有检测到它

//parent state with resolve to retrieve whiskey from service
.state('whiskey', {
            url: '/whiskey/{whiskeyId}',
            abstract: true,
            sticky: true,
            params: {
                post: null,
                index: null
            },
            resolve: {
                whiskey: [
          'Whiskey',
          '$stateParams',
          function (Whiskey, $stateParams) {
            console.log('$stateParams ', $stateParams)
            return Whiskey.show($stateParams.whiskeyId).then(function (whiskey) {
                return whiskey
            })
         }
      ]},
            views: {
                'main': {
                    templateUrl: '/views/whiskey/whiskey-header.html',
                    controller: 'Whiskey-headerCtrl'
                }
            }
        })

 //child state does not work on page refresh, just shows json data
.state('whiskey.whiskey-post', {
            url: '',
            views: {
                'whiskey-child': {
                    templateUrl: '/views/whiskey/whiskey-post.html',
                    controller: 'Whiskey-postCtrl'
                }
            }
        })  

 //child state is working fine
.state('whiskey.whiskey-about', {
            url: '/about',
            views: {
                'whiskey-child': {
                    templateUrl: 'views/whiskey/whiskey-about.html',
                    controller: 'Whiskey-aboutCtrl'
                }
            }
        })
我的服务:

'use strict';
angular.module('clientApp').factory('Whiskey', function ($http, $q) {
  var currentWhiskey = { _id: 'init' };
  return {
    show: function (whiskeyId) {
      if (currentWhiskey._id !== whiskeyId) {
        return $http.get('whiskey/' + whiskeyId).then(function (res) {
          currentWhiskey = res.data;
        return   $q.when(currentWhiskey);
        });
      } else {
        return $q.when(currentWhiskey);
      }
    },

});
我还将在下面添加控制器:

//whiskey-header ctrl for parent state
'use strict';
    angular.module('clientApp').controller('Whiskey-headerCtrl', function (         $scope, whiskey) {

  $scope.whiskey = whiskey;

});
威士忌邮政总监:

'use strict';
angular.module('clientApp').controller('Whiskey-postCtrl', function ($state, $scope, Post, PostVote, Whiskey, $location, Voter) {

  $scope.post = [];

  $scope.queryObject = {
    sorter: 'timestamp',
    sort: { 'timestamp': -1 },
    skip: 0
  };

  $scope.sort = function (a) {
    var ascend = {};
    ascend[a] = 1;
    var descend = {};
    descend[a] = -1;
    if (_.isMatch($scope.queryObject.sort, descend)) {
      $scope.queryObject.sort = ascend;
      $scope.queryObject.sorter = a;
    } else if (_.isMatch($scope.queryObject.sort, ascend)) {
      $scope.queryObject.sort = descend;
      $scope.queryObject.sorter = a;
    } else {
      $scope.queryObject.sort = descend;
      $scope.queryObject.sorter = a;
    }
    $scope.post = [];
    $scope.isBusy = false;
    $scope.queryObject.skip = 0;
    $scope.loadMore();
  };

  $scope.loadMore = function () {
    if ($scope.isBusy === true) {
      return;
    }
    $scope.isBusy = true;
    Post.getPost({
      'queryObject': $scope.queryObject,
      'filter': { 'whiskey': $scope.whiskey._id }
    }).then(function (res) {
      if (!res.data.length) {
        $scope.isBusy = true;
        return;
      }
      if (res.data.errmsg) {
        toastr.error(res.data.errmsg);
      } else {
        if ($scope.post) {
          $scope.post.push.apply($scope.post, res.data);
        } else {
          $scope.post = res.data;
        }
        $scope.queryObject.skip += res.data.length;
        $scope.isBusy = false;
      }
    });
  };

    $scope.loadMore();
});
我明白了

这与我的服务器端代码冲突

我使用的是“漂亮url”/html5模式,它从浏览器url中删除哈希

该状态与我的服务器上的此路由匹配:

app.get('/whiskey/:id', whiskeys.show);
因此,这就是它为请求发回纯json的原因

找到了答案

这与我的服务器端代码冲突

我使用的是“漂亮url”/html5模式,它从浏览器url中删除哈希

该状态与我的服务器上的此路由匹配:

app.get('/whiskey/:id', whiskeys.show);
因此,这就是它为请求发回纯json的原因

有关公用服务器的重写规则配置,请参阅。有关公用服务器的重写规则配置,请参阅