Angularjs - 无法使用参数访问url

时间:2017-08-30 13:40:40

标签: angularjs url url-parameters angularjs-ng-route

我有以下代码用于路由到调查。当我从我的角度应用程序中的另一个部分访问它时,就像这样 '../fill/'+ $ scope.fill [i] .id; 这导致此网址为“http://localhost:9000/fill/27”,一切正常。 但是当我刷新页面或直接使用url点击它时,它不会加载任何内容,并且尽管我在同一个html中添加了所有必需的源代码,但这些错误都没有找到源文件。

var app = angular.module('mainApp', ['ngRoute']);

app.config(['$routeProvider', '$locationProvider',
function($routeProvider, $locationProvider) {

    $locationProvider.html5Mode({
      enabled: true,
      requireBase: false
    });
    $routeProvider
      .when('/fill/:id', {
        templateUrl: 'fill.html',
        controller: 'fillCtrl'
      })
      .otherwise({
        redirectTo: '/'
      })
  }
]);

app.controller('fillCtrl', ['$scope', '$location', '$http', '$routeParams', function($scope, $location, $http, $routeParams) {
  $scope.id = $routeParams.id;
  console.log($scope.id);
}]);

0 个答案:

没有答案
相关问题