Suggestion Box - problem with hashing anchors/routing - need help


Hello, I started Suggestion Box project and everything went easy until i started adding routing to my app. I'm using Brackets as my text editor, and its Live Preview option makes local server where i can run the app.

<!DOCTYPE html>
        <title>Suggestion Box</title>
        <link rel="stylesheet" type="text/css" href="css/main.css">
        <link href="
css/bootstrap.min.css" rel="stylesheet"> 
        <script type="text/javascript" src="js/vendor/angular.min.js"></script>
        <script src="" type="text/javascript"></script>
    <body ng-app="SuggestionBox">
        <div ng-view></div>
        <!-- Modules  -->
        <script src="js/app.js"></script>
        <!-- Controllers  -->
        <script src="js/controllers/HomeController.js"></script>
        <script src="js/controllers/SuggestionController.js"></script>
        <!-- Services -->
        <script src="js/services/suggestions.js"></script>


<h1>{{ helloWorld }}</h1>
<a href="#/about">About</a>
        <div ng-repeat="post in posts | orderBy: '-upvotes'">
            <p>{{ post.title }}</p>
            <!-- <p>{{ post.upvotes }}</p> -->
            <p><span class="glyphicon glyphicon-plus-sign" ng-click="upVote(post)"></span> Upvotes: {{post.upvotes}}</p>
            <a href="#/suggestion/{{$index}}" target="_self">Comments</a>
        <form ng-submit="addSuggestion()" style="margin-top: 50px">
          <h3> Submit Your Suggestion </h3>
          <div class="form-group">
            <input type="text" class="form-control" placeholder="Great ideas here" ng-model="title"></input>
          <button type="submit" class="btn btn-primary">Suggest</button>

My app.js file:

var app = angular.module("SuggestionBox", ['ngRoute']);
app.config(["$routeProvider", function($routeProvider){
        controller: "HomeController",
        templateUrl: "views/home.html"
        controller: "SuggestionController",
        templateUrl: "views/suggestion.html"
    .when('/about', {
        controller: "AboutController",
        templateUrl: "views/about.html"
        redirectTo: '/'


app.controller("HomeController", ["$scope", "suggestions", function($scope, suggestions){
    $scope.helloWorld = "Hello Angular JS!";
    $scope.posts = suggestions.posts;
    $scope.addSuggestion = function(){
      if(!$scope.title || $scope.title === ""){
          title: $scope.title,
          upvotes: 0,
          comments: []
      $scope.title = ""; //clearing input
      $scope.upVote = function(post){
      post.upvotes += 1;  


app.controller("SuggestionController", ["$scope", "$routeParams", "suggestions", function($scope, $routeParams, suggestions){
    $ = suggestions.posts[$].comments;
    $scope.addComment = function(comment){
    $scope.hello = "Hello comments";

In my index.html everything is included, no console error occur, i got ng-view set up correctly, because
when i run Live Preview the url in browser is!/ and it shows views/home.html template correctly. My problem starts when i click certain comment.
When i click first one the url changes to:!/#%2Fsuggestion%2F0
When i click first one the url changes to:!/#%2Fsuggestion%2F1
When i click first one the url changes to:!/#%2Fsuggestion%2F2

etc. but NOTHING HAPPENS. The url changes as expected but the view doesnt change at all. However, if I manually change the url in the browser, let's take the first example, for!/suggestion/0 it shows exactly the template i want. Has anybody come accross this problem already? I tried some different solutions already, for example using $locationProvider. i used html5mode(true); and tried changing the anchor links. Tried using target="_self" in anchors. Even tried not using $locationProvider and even disabling bootstrap which might use it. It always redirects to some hashed link and nothing happens, only manual exact input. Do you think it might be a problem with Brackets' Live Preview specifics? The server or something?

Everytime i check angular js codecademy projects i come to conclusion i got everything following the same pattern. And yet the linking to another view still doesn't work. :cry:


Dumb question.. Do you have this path in your local setup? You could just call the same CDN as the next script and have a current version.


No question are dumb, take any question you want. If i hadn't it on my local setup there would be console errors. I have it downloaded and it sits in js/vendor file under the angular.min.js name.

I see all the demo suggestions in the main view. just when i click on one of them only the url changes - the view does not :frowning:


Can I pester you for a link to this project, please? I need to get a closer look. Thanks.


should i upload whole project folder and post a link here? or should i copy paste every file? i know there's thing called GitHub, but I didn't use it yet tho. Just tell me your preference and I'll gladly do it :slight_smile:


Nothing so detailed. I only need to see the course page.


It's the final project


We seem to be missing the suggestions.js service. Do you have that?



app.factory('suggestions', [function(){
  var demoSuggestions = {
    posts: [
        title: 'Free pizza at club meetings',
        upvotes: 15,
        comments: ['is it free tho?', 'nice!']
        title: 'End all club emails with Laffy Taffy jokes',
        upvotes: 9,
        comments: ['he he hu he hu ha ha', 'holy christ']
         title: 'Retrofit water fountain with Gatorade',
         upvotes: 3,
         comments: ['holy moly', 'stupid idea']
         title: 'Sing Bon Jovi\'s "Living on a Prayer" halfway through meetings',
         upvotes: 7,
         comments: ['not funny']
  return demoSuggestions;

I know my comments are so creative.

When i hit Live Preview in Brackets the url in browser is!/ and i see all the comments - just as expected. Before i used routing, the ng-repeat part was in index.html and the look of my app was exactly the same. The problem is only when i click on a comment or 'about'. Then the url change (gave examples in 1st post) but the view doesn't change at all. Only when i input!/suggestion/0 or!/suggestion/"here put comment index.." i see the view i want to see, which is the array of posts' comments.


I'm a little mystified by the ! in that URL, but may have just forgotten some basics. Haven't done any AngularJS in ages. I was sure I had done this but cannot find it on this machine. Must be on the laptop.

Could be I've stared at this code for too long to be objective anymore. Time for someone else to chime in and relieve me. Gotta go. Sorry I couldn't be of any help.


these all all the files. The directories on my computer are:

There's all the files if anyone is interested in the case. Thanks for effort!


I would prefer to just copy and paste from here, if it's all the same. We're still missing,

SuggestionBox.js // edited.

Add to that,




app.controller("AboutController", ["$scope", function($scope){
     $scope.testMessage = "test";


<div><h1>{{ testMessage }}</h1></div>


    <h1> {{ post }}</h1>


I found a solution! I will later edit this post to tell everybody the solution, maybe one day it will help some one. Special thanks to @mtf for effort!

The whole problem was caused by one thing. I had the newest angular 1 version. I believe codecademy didn't use the newest. In version i downloaded - 1.6.1 they decided to set $locationProvider.hashPrefix('"!");
which was the cause of my problem.. My fix was to use $locationProvider.hashPrefix(""); Now it works like a charm. Please close the topic and leave it so somebody in the future could use it :). Here is my fixed code:

var app = angular.module("SuggestionBox", ['ngRoute']);
app.config(["$routeProvider", "$locationProvider", function($routeProvider, $locationProvider){
        controller: "HomeController",
        templateUrl: "views/home.html"
        controller: "SuggestionController",
        templateUrl: "views/suggestion.html"
    .when('/about', {
        controller: "AboutController",
        templateUrl: "views/about.html"
        redirectTo: '/home'


Ah, so it was that nasty ! after all. That's two person-days we won't get back but I'm glad you solved it. Whew!