Nihar Chandurkar
Nihar Chandurkar

Reputation: 13

Route does not work nor it loading html views

Can anybody Help, Route does not work nor it loading html views

https://plnkr.co/edit/yN1gi4urwWczedcCilbD

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

hallApp.config(['$routeProvider', function($routeProvider) {
   $routeProvider.when('/home', {
      templateUrl: 'home.html', 
      controller: 'homeCtrl'

   }).when('/income', {
      templateUrl: '../../views/income.html', 
      controller: 'incomeCtrl',
      css: '../../css/income.css'
   }).when('/expense', {
      templateUrl: '../../views/expense.html', 
      controller: 'expenseCtrl',
      css: '../../css/expense.css'
   }).when('/profitandloss', {
      templateUrl: '../../views/profitandloss.html', 
      controller: 'profitandlossCtrl',
      css: '../../css/profitandloss.css'
   }).otherwise({
      redirectTo: '/home'
   });

}]);

hallApp.controller('homeCtrl', ['$scope', function($scope) {
  $scope.greeting = 'Home!';
}]);

Can anybody Help, Route does not work nor it loading html views

Upvotes: 1

Views: 43

Answers (1)

Derlin
Derlin

Reputation: 9891

In your Plunkr, you are redefining HallApp, so your routes disappeared:

var hallApp = angular.module("hallApp",['ngRoute']); // <- first define

hallApp.config(...);

hallApp.controller('homeCtrl', ['$scope', function($scope) {
  $scope.greeting = 'Home!';
}]);

var hallApp = angular.module('hallApp', []); // <- second define
hallApp.controller('newCtrl', function($scope) {
 // create a message to display in our view
 $scope.message = 'Everyone come and see how good I look!';
});

Remove the "second define" and you will be fine (fixed Plunkr here).


Note: in angular, the syntax:

angular.module('app', [])

and

angular.module('app')

have a different meaning. The first creates a new module, the second returns a reference to an existing module. So there should only be one call to module(string, array) with the same string !

Upvotes: 2

Related Questions