2014-12-02 45 views
0

我有我的角度应用程序使用路由和两个视图。从视图2到视图1的角度链接不刷新页面

当第二个观点,我只是试图重新添加一个链接以查看1,即“返回首页”

我尝试了以下内容和它的作品ofcourse,但它的作用就像一个正常的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 : '/' 
    }); 
}]); 
+0

什么是写你的网页在你的路线供应商/供应商的状态(“/”)? – 2014-12-02 11:17:03

+0

你需要处理这种情况,以及在你的路线提供者。当选项 – Kop4lyf 2014-12-02 11:17:46

+0

看起来像我必须像这样添加“" to stop the full refresh when im back in the root..is this normal ? – StevieB 2014-12-02 11:37:01

回答

0

我不知道,如果你使用的是HTML5模式与否。但首先你需要设置你的主页为“/”。

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

这之后,您可以链接到使用

<a href="#"> 
+0

Tried just the "#" still does a full page refresh – StevieB 2014-12-02 11:20:38

+0

@StevieB Are you sure that you don't have any conflicting code somewhere else? I'm pretty sure this should work – koningdavid 2014-12-02 11:22:15

+0

I added my routing to original post, but yup still doing full refresh – StevieB 2014-12-02 11:25:45