javascriptangularjsnode.jsroute-provider

How to use $routeProvider by javascript?


Is there any possibility to call "dashboard.html" without using <a href="#!dashboard">Some text</a>? I wont to call "dashboard.html" from javascript.

app.config(function($routeProvider) {
  $routeProvider
  .when('/', {
    templateUrl : 'loginRegister.html',
    controller : 'loginRegister'
  })
.when('/dashboard', {
    templateUrl : 'dashboard.html',
    controller : 'dashboard'
  })
})

app.controller('loginRegister', function($scope, $http) {
    $scope.showDashboard = function() {
         // CALL dashboard.html FROM HERE
    }
})

Solution

  • You can use the location function https://docs.angularjs.org/guide/$location

    OR you can use the $window inside AngularJS controller

    $window.location.href = '/index.html';
    

    It think you will have a complete response here How to redirect to another page using Angular JS?