2

ngRoute was previously working fine and is stopped working now ater added few files and controllers. In The browser I get URL as http://localhost/#browsefp instead of http://localhost/#/browsefp

below is my code, please help. Learning AngularJS and keep getting weird issues. No errors seen in JS console.

app.js

 var app = angular.module('DevStreamApp', ['ngRoute']);

 app.config(function($routeProvider){
 $routeProvider 
   .when('/', {templateUrl : 'views/main.html', controller : 'mainController' })
   .when('/addnew', {templateUrl : 'views/addnew.html', controller : 'homeController', css : 'css/screen.css'})
   .when('/addnewfp', {templateUrl : 'views/addnewfeeprogram.html', controller : 'homeController', css : 'css/screen.css'})
   .when('/addnewcm', {templateUrl : 'views/addnewcustomermapping.html', controller : 'aboutController', css : 'css/screen.css'})
.when('/browsefp', {templateUrl : 'views/browseprogram.html', controller : 'browseprogramController', css : 'css/screen.css'})
.otherwise({ redirectTo : '/' })
 }); 

index.html

<!doctype html>
<!-- define angular app -->
<html ng-app="DevStreamApp">
<head>
<titleFee </title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<style type="text/css" media="screen">
   @import url("/css/screen.css");
   @import url("/js/yui/container.css");
</style>

<!-- load angular and angular route via CDN -->
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular.min.js">        </script>
  <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular-route.js"></script>
  <script src="js/app.js"></script>
</head>
<body>
<hr noshade/>
 <!-- MAIN CONTENT AND INJECTED VIEWS -->
    <div id="main">
        <!-- angular templating -->
        <!-- this is where content will be injected -->
        <a href="#addnew">Add new </a><br/>  
        <a href="#addnewfp">Add new Fee Program</a><br/>  
        <a href="#addnewcm">Add new Customer mapping</a><br/> 
        <a href="#browsefp">Browse Fee Program</a>
        <div ng-view></div>
    </div>
</body>
<script src="js/app.js"></script>
<script src="js/controllers/mainController.js"></script>
<script src="js/controllers/homeController.js"></script>
<script src="js/controllers/aboutController.js"></script>
<script src="js/controllers/contactController.js"></script>
<script src="js/controllers/browseprogramController.js"></script>
</html>

mainController.js

 //create the controller module 
 angular.module('DevStreamApp').controller('mainController', function($scope) {

// create a message to display in our view
$scope.message = 'Everyone come in Main Controller!';
});
2
  • and it does not work? Commented Dec 28, 2015 at 16:35
  • Just as an aside I would recommend ui-router It is much more robust and not any harder to use than the out of the box angular router Commented Dec 28, 2015 at 16:42

2 Answers 2

1

Remove the # from the href, as you can see in doc they configure it as follow:

<a href="Book/Moby">Moby</a>

.when('/Book/:bookId', {
      ....
});

so in your case it would be:

    <a href="addnew">Add new </a><br/>  
    <a href="addnewfp">Add new Fee Program</a><br/>  
    <a href="addnewcm">Add new Customer mapping</a><br/> 
    <a href="browsefp">Browse Fee Program</a>
Sign up to request clarification or add additional context in comments.

1 Comment

post what you got in the console log
0

By default, AngularJS will route URLs with a hashtag, but you can remove it with $locationProvider.

You will use the $locationProvider module and set html5Mode to true.

 var app = angular.module('DevStreamApp', ['ngRoute']);

 app.config(function($routeProvider,  $locationProvider){
     $locationProvider.html5Mode(true);

     ... your code ...

And in your index.html the link must be

<a href="addnew">Add new </a><br/> 

3 Comments

any idea why it is not working hashtag? I dont have $locationProvider in my app.js
It was working properly until I added more code files
Just add $locationProvider in your app.js file. The line will be as follow <code>app.config(function($routeProvider, $locationProvider){</code>, remember add <code>$locationProvider.html5Mode(true);</code>. Your line now is <code>app.config(function($routeProvider){</code>

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.