2014-03-31 39 views
0

例如,有一個按鈕,在我的頁面「創建」,並已NG-單擊屬性:如何重定向到另一條路線?

<button ng-click="create()">Create</button> 

而在create()功能,我想要做的事,然後重定向到另一條路線#/show,這是angularjs定義的客戶端站點路線:

function MyCtrl($scope) { 
    $scope.create = function() { 
     // do something 
     // how to redirect to `#/show`, another view and controller will be used 
    } 
} 

回答

2
function MyCtrl($scope, $location) { 
    $scope.create = function() { 
     // do something 
     $location.path('/show'); 
    } 
} 

See $location API

相關問題