Solved

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

Posted on 2013-12-27
4
638 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to dynamically set the form action using jQuery.
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…
Suggested Courses

636 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