2

I don't understand why I can't get this to work.

I'll share the relevant code, let me know if you need to see more stuff.

Index.html

<div class="col-md-3"><a href="#/liberals">Liberals</a></div>

app.js

var app = angular.module('myApp', ['ngRoute']);
app.config(function ($routeProvider) {
    $routeProvider.
    when("/liberals", {
        templateUrl: "partials/liberals.html"
        , controller: "LiberalsController"
    });
});

app.controller('LiberalsController', function ($scope, $http) {
    var url = "workingURL"; /// changed function to a simple string message to test
    $scope.message = "Hello Liberals";
});

(partial view) liberals.html

    <h1>Hello</h1> 
     {{message}}

PS: I'm not working on a political hate website for or against liberals!

5
  • what display in console?? Commented Mar 15, 2017 at 17:04
  • Do you get any error message when the link is clicked? Commented Mar 15, 2017 at 17:05
  • the console is empty, and I get no error messages when I click the link Commented Mar 15, 2017 at 17:05
  • I've loaded the angular.js and angular.route.js, if that's what you're asking(?) Commented Mar 15, 2017 at 17:17
  • Josem, what version are u using ? 1.6+ ? Commented Mar 15, 2017 at 17:21

1 Answer 1

2

As of AngularJS 1.6, the default value of the hashPrefix has been changed to !.

There's two ways to get your routing to work with AngularJS 1.6+:

  • Add the hashprefix (!) to your href's:

<a href="#!/liberals">Liberals</a>

  • Change (remove) the hashPrefix value using $locationProvider:

$locationProvider.hashPrefix('');

I've created a working plunkr in which I used the second approach: https://plnkr.co/edit/oTB6OMNNe8kF5Drl75Wn?p=preview

The commit regarding this breaking change can be found here

Sign up to request clarification or add additional context in comments.

3 Comments

There it is! Thank you so very much!
I am facing same issue but not working !! Is there any version issue I need to correct ?
That's hard to tell. Create a plunkr and ping me at gitter.im/angular/angular.js so I can take a look at it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.