2016-07-27 107 views
0

On按鈕單擊我有代碼進行導航。


$s.onClick = function (pageObj) { 
    $location.path('/Next'); 
} 

這裏PARAM pageObj是含有鏈接對象(例如:http://sample.),標題和其他鍵的值。現在我想通過鏈接,標題PARAMS至$ location.path所以我試圖用


$location.path('/Next/' + pageObj.link + '/' + pageObj.title) 

這裏鏈接,標題PARAMS我想在接下來的頁面中使用。 pageObj.link又是http,因此完整的路由網址將無法導航。

下面是代碼路由


angularModule.config(function ($routeProvider) { 
$routeProvider 
    .when('/', { 
     templateUrl: '/www/temp/Main.html', 
     controller: 'MainController' 
    }) 
    .when('/Next', { 

     templateUrl: '/www/temp/Select.html', 
     controller: 'SelectController' 

    }) 
}); 

如何檢查PARAMS並導航到下一頁與PARAMS。我不希望這些參數在url中顯示。

回答

0

既然你不想參數出現在URL,絕對最簡單的方法是使用$rootScope這樣的:

第一頁

$rootScope.routeParams.link = "/my/link/here"; 
$rootScope.routerParams.title = "My page title here"; 

第二頁

$scope.link = $rootScope.routerParams.link; 
$scope.title = $rootScope.routerParams.title; 

注意

你需要定義$rootScope.routeParams對象在你的app.config,與此類似:

app.config(function($rootScope) { 
    $rootScope.routeParams = { 
     link: null, 
     title: null 
    } 
}); 

您還需要注入$rootScope到每個控制器,你引用它,與此類似:

app.controller('FirstPage_Ctrl', function($scope, $rootScope) { 
    $rootScope.routeParams.link = "/my/link/here"; 
    $rootScope.routerParams.title = "My page title here"; 
}); 
+0

我不想使用$ rootScope。我的要求是通過$ location發送參數 – vbharath