The AngularJs routing, the views do not appear after the link

advertisements

I just started with angular and I've been experimenting with single page website, so I've basically just created really simple html to change, such as:

login.html

<div>
    <h1>login</h1>
</div>

register.html

<div>
    <h1>login</h1>
</div>

But when I click the links below leading to login.html and register.html, nothing happens.

Index.html

<!DOCTYPE html>
<!--[if lt IE 7]>      <html lang="en" ng-app="myApp" class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html lang="en" ng-app="myApp" class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html lang="en" ng-app="myApp" class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html lang="en" ng-app="myApp" class="no-js"> <!--<![endif]-->
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>My AngularJS App</title>
  <meta name="description" content="">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="bower_components/html5-boilerplate/dist/css/normalize.css">
  <link rel="stylesheet" href="bower_components/html5-boilerplate/dist/css/main.css">
  <link rel="stylesheet" href="app.css">
  <script src="bower_components/html5-boilerplate/dist/js/vendor/modernizr-2.8.3.min.js"></script>
</head>
<body>

<a href="#login">login</a>
<a href="#register">register</a>
<div ng-view>

</div>

<script src="//ajax.googleapis.com/ajax/libs/angularjs/x.x.x/angular.min.js"></script>
<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/angular-route/angular-route.js"></script>
<script src="app.js"></script>
<script src="view1/view1.js"></script>
<script src="view2/view2.js"></script>
<script src="components/version/version.js"></script>
<script src="components/version/version-directive.js"></script>
<script src="components/version/interpolate-filter.js"></script>
</body>
</html>

And here is where my module lies

app.js

'use strict';

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

app.config(['$locationProvider', '$routeProvider', function($locationProvider, $routeProvider) {
  $locationProvider.hashPrefix('!');

  $routeProvider
      .when("/", {
        templateURL : "view/login.html",
      })
      .when("/register", {
          templateUrl : "view/register.html"
      })
      .otherwise({redirectTo: '/login'});
}]);

I'm using JetBrains WebStorm for the premade angular html file, and local server.

Thank you


Let try with this way

angular.module('myApp', ['ngRoute']);

<a href="#!login">login</a>
<a href="#!register">register</a>