1

This my app.js,

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

myApp.config(function($routeProvider){
    $routeProvider.when('/',{
        templateUrl: 'views/home.html',
        controller: 'homeCtrl'
    }).when('/detail',{
        templateUrl: 'views/details.html',
        controller: 'detailCtrl'
    }).otherwise({
        redirectTo: '/home'
    });

});

myApp.controller('homeCtrl',function($scope){
    $scope.message ="Welcome to your Home Page"
});

myApp.controller('detailCtrl',function($scope){
    $scope.message ="Name: Manish"
});

This is index.html page,

    <html >
      <head>
        <meta charset="ISO-8859-1">
        <title>Try It Out</title>
        <script type="text/javascript" src="js/angular.js"></script>
        <script type="text/javascript" src="js/angular-route.js"></script>
        <script type="text/javascript" src="js/app.js"></script>
      </head>
     <body ng-app="myApp" ng-controller="homeCtrl" style="text-align: center;">
        <span ><a href="/">{{message}}</a></span><br>

        <a href="#/">Home</a>&nbsp;&nbsp;
        <a href="#/detail">Details</a>

        <br><br>
        <div ng-view></div>

        <h4>copyright 2017</h4>
      </body>
   </html>

this is my home.html

<h3>Home</h3><br>
 {{message}}

same in details.html

<h3>Details</h3><br>
 {{message}}

problem is when i run it on server its going to home page at first.but when i click on details..its not showing message of Details.html. and main problem is with URL...clicking on Details link..

http://localhost:7675/AngularJSinglePage/#!/#%2Fdetail

As u can notice "!/#%2F" this comes in between..don't know from where,it should come like this

http://localhost:7675/AngularJSinglePage/#/detail

Any one faced same problem? Help me out, I am trying to learn SPA using AngularJS?

Manish
  • 61
  • 1
  • 9
  • Have you tried to remove the `#` before the `/` ? in your ` – Sherlocked Nguyen Jul 28 '17 at 06:58
  • Yup i did try removing "#" before "/" . then when i click on "Details" achor link ,then URL comes like this (http://localhost:7675/detail) but it should be like (http://localhost:7675/AngularJSinglePage/detaul) – Manish Jul 28 '17 at 07:03

1 Answers1

0

Answered @ https://stackoverflow.com/a/41273403 :)

In addition you do not have a spaController in your app.js which is referenced in your