Skip to content

Instantly share code, notes, and snippets.

@zenius
Last active June 3, 2019 12:07
Show Gist options
  • Save zenius/17b36e7ad45ecaa49de5f6d15ef9ed4f to your computer and use it in GitHub Desktop.
Save zenius/17b36e7ad45ecaa49de5f6d15ef9ed4f to your computer and use it in GitHub Desktop.
If you want to navigate to different pages in your application, but you also want the application to be a SPA (Single Page Application),
with no page reloading, you can use the ngRoute module.
Applications can only have one ng-view directive, and this will be the placeholder for all views provided by the route.
<div ng-view></div>
With the $routeProvider you can define what page to display when a user clicks a link.
var app = angular.module("myApp", ["ngRoute"]);
app.config(function($routeProvider) {
$routeProvider
.when("/", {
templateUrl : "main.htm"
})
.when("/london", {
templateUrl : "london.htm"
})
.when("/paris", {
templateUrl : "paris.htm"
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment