0

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 : '/'
 });
});  
CrazyMac
  • 462
  • 4
  • 19

2 Answers2

1

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'

]);
Gayathri Mohan
  • 2,924
  • 4
  • 19
  • 25
0

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 ?

  • Here is my router code, Project.config(function($routeProvider) { .when('/proposal', { templateUrl : '/Project/proposal', controller : 'homeController' }).otherwise({ redirectTo : '/' }); }); I have added the router code in my main post as well – CrazyMac Jun 17 '16 at 03:06