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

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

Suppose you are using routes:

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

    $rout         


        
8条回答
  •  日久生厌
    2020-11-30 17:11

    Routes monitor the $location service and respond to changes in URL (typically through the hash). To "activate" a route, you simply change the URL. The easiest way to do that is with anchor tags.

    Go Home
    Go to About
    

    Nothing more complicated is needed. If, however, you must do this from code, the proper way is by using the $location service:

    $scope.go = function ( path ) {
      $location.path( path );
    };
    

    Which, for example, a button could trigger:

    
    

提交回复
热议问题