从视图2到视图1的角度链接,无需刷新页面

时间:2014-12-02 11:11:12

标签: javascript angularjs

我的角度应用程序使用路由和两个视图。

在第二个视图中,我只是想添加一个链接回到视图1,即“返回主页”

我尝试了以下内容并且它的工作原理,但它的行为就像一个正常的href并刷新页面

<a href="/">Back to Search</a>

如何在没有完整页面刷新的情况下添加链接,只是更改视图?

编辑添加的路由配置

app.config(['$routeProvider','$locationProvider', function($routeProvider,$locationProvider){
  $routeProvider
    .when('/',{
      templateUrl: '/views/main.html',
      controller : 'SearchCtrl'
    })
    .when('/result',{
      templateUrl: '/views/result.html',
      controller : 'resultCtrl'
    })
    .otherwise({
      redirectTo : '/'
    });
}]);

1 个答案:

答案 0 :(得分:0)

我不确定您是否使用HTML5模式。但首先,您需要将主页设置为&#34; /&#34;。

$routeProvider
    .when('/', {
        templateUrl : 'pages/home.html',
        etc....
    })

在此之后,您可以使用

链接到您的主页
<a href="#">