HardLuckHank
HardLuckHank

Reputation: 29

Routing javascript file not found using Angular-route

I am building a simple angular frontend page to display some simple html pages and am trying to get angular-route to work correctly. I have a Nav bar at the top and I want to have a view displayed below it where I can change out the html pages within that view. I have a routing.js file with the controllers and routing infomation being referenced from the main html page. My problem is that non of my views are being displayed. When I check the webpage console to see why the views aren't being displayed it returning a 404 Not Found. I'm not sure why considering I have the routing.js file right in root. Here is my index.html page with the nav bar and where the views should be showing.

    <!DOCTYPE html>


<html>

  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="../../favicon.ico">

    <title>Register License Plate</title>

    <!-- Libraries -->


<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>

<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-route.js"></script>

<!-- to get routing information and controllers -->
<script src="routing.js"></script>

</head>

<body>

<div ng-app = "plateApp" ng-controller = "defaultController">

<!-- NAV BAR -->
<nav class="navbar navbar-default">
  <div class="container-fluid">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" a href = "/">LPR</a>
    </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav">
        <li class="active"><a href="#register">Register License Plate <span class="sr-only">(current)</span></a></li>
        <li><a href="#payticket">Pay Ticket</a></li>
      </ul>
      <form class="navbar-form navbar-right" role="search">
        <div class="form-group">
          <input type="text" class="form-control" placeholder="Enter Lot Number">
        </div>
        <button type="submit" class="btn btn-default">Submit</button>
      </form>
      <form class="navbar-form navbar-right" role="search">
      <button type="submit" class="btn btn-default">Submit</button>
        <div class="form-group">
          <input type="text" class="form-control" placeholder="Enter Plate Number">
        </div>
      </form>
    </div><!-- /.navbar-collapse -->
  </div><!-- /.container-fluid -->
</nav>

</div>


<!-- Show views here -->
<div id="main">

<div ng-view></div>

</div>

<!-- Test words to show something is being displayed after the view is displayed -->
After View is Displayed


  </body>

</html>

I'm at a loss considering I reference the routing.js script. I am new to angular js so I am doing something wrong obviously. Below is my routing.js script as well.

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

plateApp.config(function($routeProvider) {
    $routeProvider

    // route for default/welcome page
    .when('/', {
        templateUrl : 'default.html',
        controller  : 'defaultController'

    })
    // route for Register LP Page
    .when('/register', {
        templateUrl : 'register.html',
        controller  : 'registerController'

    })

    // router for Paying Tickets page
    .when('/payticket', {
        templateUrl : 'payticket.html',
        controller  : 'payticketController'
    })

    // route for getting plates and Lot page
    .when('/getplates', {
        templateUrl : 'getplates.html',
        controller  : 'getPlatesController'
    });
});

//Controllers
plateApp.controller('defaultController', function($scope){
    //Keeps scopes and other Vars here
    $scope.testMessage = 'Welcome to this website';
});

plateApp.controller('registerController', function($scope){
    //Keeps scopes and other Vars here
    $scope.testMessage = 'Register your plates';
});

plateApp.controller('payticketController', function($scope){
    //Keeps scopes and other Vars here
    $scope.testMessage = 'Pay Tickets';
});

plateApp.controller('getPlatesController', function($scope){
    //Keeps scopes and other Vars here
    $scope.testMessage = 'Get Plates from SQLdb';
});

Also some background info on how the server is being run. I have a linux box running node and express on port 1337

When I type in the address to the server which is 192.168.239.130:1337/ I have it sending back the index.html page. This loads fine and I am able to see the nav bar/webpage except I don't see the views of the other html pages being loaded because apparently the routing.js file isn't found.

Any help would be appreciated.

Thanks.

Upvotes: 1

Views: 1580

Answers (1)

Pratik Bhattacharya
Pratik Bhattacharya

Reputation: 3746

Looks like an issue with the template URL. Ensure that the path that you are providing as the template URL is a relative URL.

So for example if your templates (HTML) for the view is present in a folder called 'Views' then your template URL should be '/views/default.html', provided that the 'Views' folder is at the root level.

Upvotes: 1

Related Questions