Home Angularjs route on button click is not working
Reply: 0

Angularjs route on button click is not working

user1695
1#
user1695 Published in June 19, 2018, 2:27 pm

I have been trying to make a angularjs application where I want to route to a different html page on a button click. But is not working for some unknown reasons.

My html code

<!DOCTYPE html>
<html ng-app="app">

  <head>
    <script data-require="angular.js@*" data-semver="1.3.0-beta.5" src="https://code.angularjs.org/1.3.0-beta.5/angular.js"></script>
     <script data-require="angular.js@*" data-semver="1.3.0-beta.5" src="https://code.angularjs.org/1.3.0-beta.5/angular-route.js"></script>
     <link rel="stylesheet" href="style.css" />
    <script src="script.js"></script>
  </head>

<body ng-controller="Controller">
<h1>Plunkr Example</h1>
  <button ng-click="changeview()">ClickMe</button>
  <h1>MainPage</h1>
</body>
</html>

My Code

var app = angular.module("app", ['ngRoute'])

app.config(['$locationProvider', function($locationProvider) {
  $locationProvider.hashPrefix('');
}]);

app.config(['$routeProvider',
  function ($routeProvider) {
      $routeProvider.
        when('/Details', {
            templateUrl: 'details.html'
        }).
        when('/Main', {
             templateUrl: 'main.html'
         }).
        otherwise({
            redirectTo: '/Main'
        });
  }]);

app.controller("Controller", function($scope,$routeParams,$location){
  //$scope.ProductId = $routeParams.id;
  $scope.changeview = function () {
        console.log('in function changeview');
        $location.path('/Details');
    }
})

Here is my plunkr

Please help.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.437959 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO