简体   繁体   English

$ routeProvider没有传递搜索参数路由

[英]$routeProvider not passing search parameter route

I'm trying to create a toggle that switches between two tables on one page. 我正在尝试创建一个在一页上的两个表之间切换的切换。 I have both the tables defined in my index.html within a <body ng-app="main"> tag as 我在index.html中的<body ng-app="main">标记中都定义了两个表,分别是

<script type="text/ng-template" id="table1.html">
    some code
 </script>

and

<script type="text/ng-template" id="table2.html">
   some code
</script>

My $routeProvider is then defined in my .js as 然后在我的.js中将$routeProvider定义为

app.config(['$routeProvider', function ($routeProvider){
   $routeProvider.when('/?table=table1', {
      controller:'PostsCtrl',
      templateUrl: 'table1.html'
   })
   $routeProvider.when('/?table=table2', {
      controller: 'PostsCtrl',
      templateUrl: 'table2.html' 
   })

    $routeProvider.otherwise({redirectTo: '/?table=table1'});
}]);

app.config(['$locationProvider', function($locationProvider){
    $locationProvider.html5Mode(true).hashPrefix('!');
}]);

ngRoute as been added as a dependency, the controller has been defined and the search parameter was added to the URL by an href surrounding each button in a btn-group. 已将ngRoute添加为依赖项,已定义控制器,并且通过围绕btn-group中每个按钮的href将搜索参数添加到URL。 I am supposed to be able to click either button and it will switch to the table but right now all that happens when I click the buttons are the page refreshing and the search parameter updating accordingly. 我应该能够单击任意一个按钮,它将切换到表格,但是现在,当我单击按钮时,发生的所有事情都是页面刷新和搜索参数相应更新。 Anyone know why $routeProvider doesn't seem to be routing to my .html? 有人知道为什么$routeProvider似乎没有路由到我的.html吗?

通过在与ng-app标签相关的close标签之前紧接<div ng-view></div>解决了该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM