-1

For some reason im not sure about my ngRoute here is not working properly. Please help me thankyou. Here is my cloud9 file where you can see live preiview and edit code. And here is my script.js:

var app = angular.module('ChattApp', ["firebase", "ngRoute"])


app.config(["$routeProvider",  function($routeProvider){

  $routeProvider
    .when('/', {
      templateUrl: 'HtmlFiles/login.html',
      controller : 'LoginController.js'
    })

    .otherwise({
      redirectTo: '/'

    })
    //Talk In Chat/Group Chat. I have to go to school now..


}]
)

app.factory("Auth", ["$firebaseAuth",
  function($firebaseAuth) {
    var ref = new Firebase("https://uniquecoders.firebaseio.com/");
    return $firebaseAuth(ref);
  }
]);
Alexander Elgin
  • 6,796
  • 4
  • 40
  • 50
amanuel2
  • 4,508
  • 4
  • 36
  • 67
  • `not working properly` isn't a proper problem description. ALso that link requires logging in and is therefore worthless. Create a demo in [plunker](http://plnkr.co/edit/?p=catalogue) that replicates problem – charlietfl Jan 14 '16 at 00:42
  • Are you loading the correct files?.. check if you don't have syntax error in LoginController.js – Oscar Reyes Jan 14 '16 at 00:42
  • Provider your controller's code – Oscar Reyes Jan 14 '16 at 00:43

2 Answers2

1

Remove app definition in all controller files.. as app is already defined in another script.. the cause is that the variable is being redefined for each loaded controller file..

please check http://www.w3schools.com/js/js_scope.asp for variable scope lifetimes

Oscar Reyes
  • 4,223
  • 8
  • 41
  • 75
0

Controller inside the object for the ".when" method takes controller name which is registered via angular not a 'js' file containing the controller's code. When you register the controller you use the method Controller(name, constructor). Then name you place as the first argument is the "name" of the controller that you are registering with angular.

controller : 'LoginController.js' Should be: controller : 'LoginController'

References: Route Docs, Controller Docs

Search for "Route" on this page and then look at the controller object properties.

Goblinlord
  • 3,290
  • 1
  • 20
  • 24
  • I added a bit more explanation as to where "name" come's from. – Goblinlord Jan 14 '16 at 02:58
  • Thats exactly what i did: app.controller('LoginController', ["$firebaseAuth", "$scope", function(){ }] ) – amanuel2 Jan 14 '16 at 02:58
  • No for the Route you need the controller set to the controllers "name". You have ```controller : 'LoginController.js'``` in the code above. It needs to be ```controller: 'LoginController'``` – Goblinlord Jan 14 '16 at 03:00