2014-12-02 44 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