Suppose you are using routes:
// bootstrap
myApp.config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) {
$routeProvider.when('/home', {
templateUrl: 'partials/home.html',
controller: 'HomeCtrl'
});
$routeProvider.when('/about', {
templateUrl: 'partials/about.html',
controller: 'AboutCtrl'
});
...
And in your html, you want to navigate to the about page when a button is clicked. One way would be
<a href="#/about">
... but it seems ng-click would be useful here too.
- Is that assumption correct? That ng-click be used instead of anchor?
- If so, how would that work? IE:
<div ng-click="/about">
Here's a great tip that nobody mentioned. In the controller that the function is within, you need to include the location provider:
Using a custom attribute (implemented with a directive) is perhaps the cleanest way. Here's my version, based on @Josh and @sean's suggestions.
It has some useful features, but I'm new to Angular so there's probably room for improvement.