2

I am new to Angular and I am having issues with Routing. When I go to localhost/index.html#/chatroom, it doesn't load Chatroom.html. Please consider the following files. Any help would be appreciated.

Following is my core.js file:

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

function mainController($scope) {

 console.log("yay");

}

function routing($routeProvider) {
    $routeProvider.when('/chatroom', {
        templateUrl : 'templates/ChatRoom.html',
        controller  : 'mainController'
    });
}
messagingApp.config(routing);
messagingApp.controller('mainController',mainController);

Following is my index.html file:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="css/style.css">
    <script src="https://cdn.socket.io/socket.io-1.4.5.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.0/angular.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-route.js"></script>

    <script src="js/User.js"></script>
    <script src="js/core.js"></script>

    <title>Real Time Chat</title>
</head>

<body ng-app="messagingApp">
<p>ss</p>

<div ng-view>

</div>

Following is my ChatRoom.html:

<div class="row">
    <p>ssss</p>
    <ul class="users">
        <li ng-repeat="user in users">{{ user.UserName }}</li>
    </ul>
</div>

Directory structure:

-js
  core.js

-templates
 ChatRoom.html

-index.html

Going to localhost/index.html#chatroom should load that file as per my understanding but it doesn't.

2
  • getting any errors in console? Commented Dec 17, 2016 at 13:18
  • @SaEChowdary None Commented Dec 17, 2016 at 13:31

2 Answers 2

-1

You shouldn't used localhost/index.html#chatroom. Please changed it to localhost/#/chatroom

Sign up to request clarification or add additional context in comments.

9 Comments

no it shows "ss" from the <p></p> tag before the ng-view div
Look like it could not found the routing instead. Please change you code to this .. messagingApp.config(function ($routeProvider) { // Routing code here });
Still nothing. One thing to note is that when I press on "localhost:8080/#/chatroom" it changes it to "localhost:8080/#!#%2Fchatroom" but that was happening before the last change as well
What? invalid char is added in front routing path. Try using html5 mode that can cut all hashtag. Set this code in under $routingProvider. $locationProvider.html5Mode({enabled: true, requireBase: false, rewriteLinks: true})
and change the url to localhost:8080/chatroom
|
-1

Add your script tags after ng-view div

2 Comments

which script tags? all of them?
@fur866 Yes all script tag below ng-view

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.