Solved

angular my links keep posting back if I try to use html 5 mode

Posted on 2013-12-27
4
633 Views
Last Modified: 2013-12-27
I can get my angular routing working using /#/page without posting back.  When I change to html5Mode, I can successfully remove the "/#" and show the right controller, but the page keeps posting back.  It is an asp.net mvc application, but I don't think that matters.  The link I click on is all html, so there should be no asp.net interaction.  

I am looking to get rid of the hashmark in the link.


My link which works but causes a post back
<a href="/angular/grid">Grid</a>

Link works without a postback in non-html5mode
<a href="/#/angular/grid">Grid</a>


My app.js file.  This is the version without the /#, If I were to add it to the links and remove the html5mode line, it works, but with the hashes.

'use strict';
var jTradeApp = angular.module('jTradeApp', ['ngTable']);

jTradeApp.config(function($locationProvider, $routeProvider) {
    $locationProvider.html5Mode(true);
    $routeProvider
        .when('/angular/grid', {
            templateUrl: '/templatesangular/PositionsGrid.html',
            controller: 'TradeGridController'
        })
        .when('/angular/error', {
            templateUrl: '/templatesangular/Error.html',
            controller: ''
        }).otherwise({ redirectTo: '/angular/grid' });
});

Open in new window

0
Comment
Question by:jackjohnson44
  • 2
  • 2
4 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 39742102
which browser?
0
 

Author Comment

by:jackjohnson44
ID: 39742123
IE, Chrome
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 39742254
be sure your ng-view tag is inside your application and controller.

Test page : http://jsfiddle.net/LLAaR/2/
0
 

Author Comment

by:jackjohnson44
ID: 39742317
Thanks for your help.  My actual issue was a surrounding div with a class "sidebar-nav".  I have a boilerplate starter css page which I was using.  I changed the class and everything started working.  I used your links and found that when they were at the bottom of the page my app worked, when they were in the div, they didn't work.
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question