How/when to use ng-click to call a route?

前端 未结 8 989
时光说笑
时光说笑 2020-11-30 16:32

Suppose you are using routes:

// bootstrap
myApp.config([\'$routeProvider\', \'$locationProvider\', function ($routeProvider, $locationProvider) {

    $rout         


        
相关标签:
8条回答
  • 2020-11-30 17:32

    Here's a great tip that nobody mentioned. In the controller that the function is within, you need to include the location provider:

    app.controller('SlideController', ['$scope', '$location',function($scope, $location){ 
    $scope.goNext = function (hash) { 
    $location.path(hash);
     }
    
    ;]);
    
     <!--the code to call it from within the partial:---> <div ng-click='goNext("/page2")'>next page</div>
    
    0 讨论(0)
  • 2020-11-30 17:37

    Remember that if you use ng-click for routing you will not be able to right-click the element and choose 'open in new tab' or ctrl clicking the link. I try to use ng-href when in comes to navigation. ng-click is better to use on buttons for operations or visual effects like collapse. But About I would not recommend. If you change the route you might need to change in a lot of placed in the application. Have a method returning the link. ex: About. This method you place in a utility

    0 讨论(0)
提交回复
热议问题