Angular 1.8 ng-view not loading html pages and no errors

642 views Asked by At

Im exploring Angular 1.8 recently due to a company requirement, and Im trying to create a simple SPA, but when I try to load html templates inside my Index page using ng-view nothing happens:

Here's my project directory:

-Wapp
--pages
----home.htm
----forecast.htm
--public
----js
------app.js
--views
----index.ejs
--app.js  // This one just starts listening in local host and has ejs config for views

This is the js/app.js for angular code :

//Module
var weatherApp = angular.module('weatherApp', ['ngRoute']);

//Routes
weatherApp.config(function($routeProvider){
    $routeProvider
    .when('/home', {
        templateUrl: '../../pages/home.htm',
        controller: 'homeController'
    })
    .when('/forecast', {
        templateUrl: '../../pages/forecast.htm',
        controller: 'forecastController'
    })

});

//Controllers
weatherApp.controller('homeController', ['$scope', function($scope){
    $scope.city = 'NY';
}]);

weatherApp.controller('forecastController', ['$scope', function($scope){
    
}]);

My index.ejs view that is the main page:

<html ng-app="weatherApp">
<head>
    <hlink href="assets/style.css" type="text/css" rel="stylesheet" />

    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.0/angular.js"></script>
    <script src="https://code.angularjs.org/1.8.0/angular-route.min.js"></script>
    
    <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
    
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
    <script src="assets/js/app.js"></script>

</head>
<body ng-controller="homeController">
    
    <nav class="navbar navbar-expand-lg navbar-dark bg-primary">
        <a class="navbar-brand" href="#">Wapp</a>
        <div class="collapse navbar-collapse" id="navbarSupportedContent">
          <ul class="navbar-nav mr-auto">
            <li class="nav-item active">
              <a class="nav-link" href="#home">Home <span class="sr-only">(current)</span></a>
            </li>
            <li class="nav-item">
              <a class="nav-link" href="#!forecast">Forecast</a>
            </li>
          </ul>
        </div>
      </nav>

      <div class="container">
          <div ng-view></div>
      </div>
      
</body>
</html>

And two html templates:

home.htm:

<div class="alert alert-primary" role="alert">
    Welcome to WApp, please proced as you may need !!
</div>

And forecast.htm:

<div class="alert alert-success" role="alert">
    Forecast page
</div>

When I click home or forecast nothing shows, urls in broswer show like this:

http://localhost:3000/#!#home -- this one shows no errors but shows nothing either
http://localhost:3000/#!/forecast  -- This one gets a error : http://localhost:3000/pages/forecast.htm 404 (Not Found)

Any ideas ??

0

There are 0 answers