Solved

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

Posted on 2013-12-27
4
626 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 your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article discusses how to create an extensible mechanism for linked drop downs.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn how to dynamically set the form action using jQuery.
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)

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now