I have the following AngularJS routing setup.
.config(function($stateProvider, $urlRouterProvider){
//some code
.state('app.edit', {
url: '/edit/:recipeId',
views: {
'menuContent': {
templateUrl: 'templates/recipes/edit.html',
controller: 'editRecipeCtrl'
}
}
//some code
});
$urlRouterProvider.otherwise('/app/home');
<a ng-click="editDemo()" href='#'>Edit</a>
The problem is when I click the link, it does not go to the edit page. (following are the observations)
http://localhost/#/app/edit/1
in the address bar , it workseditDemo()
method.$scope.editDemo = function(){
// options I tried
// $location.path( '/edit/1' );
// $location.path( '#/app/edit/1');
// $location.path( 'edit/1');
// $location.url( '/edit/1' );
// $location.url( '#/app/edit/1' );
// $location.url( 'edit/1');
// location.href = '/#/app/edit/1';
}
I prefer (to prevent pitfalls) to use the $state service
$scope.editDemo = function(id) {
$state.go('app.edit', {recipeId: id});
}