Reputation: 462
I am using Angular and trying to route to a page. It works everywhere but in the code below, when I try to route, I see the URL moving to the desired page but comes back to the same page from where it was triggered. I am not sure why is it behaving like this.
This is my HTML from where I call a method
<button ng-click="proposalForm()" >Request</button>
In my controller.js, I am just trying to route to a different page. When I click the button, it routes to the proposal page but quickly returns to the same from where I trigger this. Am I missing any? It works for me in all other places.
$scope.proposalForm = function() {
$location.path('/proposal');
}
When I try to access this using datatarget, it includes the JSP but when I try to route completely to a different page, it doesn't work. Is there any other way, I can route it to a different JSP.
Here is my router code, It has the correct path for proposal, I am not sure if it is routing to the default for some reason
Bid.config(function($routeProvider) {
.when('/proposal', {
templateUrl : '/Bid/proposal',
controller : 'homeController'
}).otherwise({
redirectTo : '/'
});
});
Upvotes: 0
Views: 56
Reputation: 2962
Use the library in your project
<script data-require="ui-router@*" data-semver="0.2.8" src="http://angular-ui.github.io/ui-router/release/angular-ui-router.js"></script>
and then config.js
.state('proposal', {
url: '/proposal',
templateUrl: 'templates/proposal.html',
controller: 'NewCtrl'
});
$urlRouterProvider.otherwise('/auth/login');
and in controller
app.controller('NavCtrl', function ($scope, $location, $state, Post, Auth) {
$scope.create = function() {
$state.go("proposal");
};
});
and app.js
var abc= angular.module('abc', [
'ui.router'
]);
Upvotes: 1
Reputation: 84
If you want to create a Single Page application ( SPA ) using AngularJS , you should use the $state service , not the $location service. Anyway, the code seems correct syntaxically speaking , maybe you can add the router code ?
Upvotes: 0