0

I configured a small angular app in tomcat its working fine, but when i tried to use route-Provider its not working. I cannot route to my views. I did not know why ?

Can any one give some small example for that.

My Code files

//this is controllers.js
var myapp = angular.module('sampleapp', []);
myapp.config('$routeProvider',function myRoute($routeProvider) {
    $routeProvider.
    when('/', {
        templateUrl: 'partials/admin.html',
        controller: 'adminController'
      })
      when('/showdata', {
          templateUrl: 'partials/data-view.html',
          controller: 'dataController'
        }).
      otherwise({
        redirectTo: '/'
      });
  });


adminController = function ($scope) {
    $scope.message = "Welcome to Login Page";
}

dataController = function ($scope) {
    $scope.message = "Welcome to Show Data Page";
}

myapp.controller(controllers)

my index.html

<html>
<base href="/advangularjs/" />
<head>
<link type="text/css" rel="stylesheet" href="css/default.css">
<script src="js/angular.js"></script>
<script src="js/angular-route.js"></script>
<script src="demoweb_angular/controllers.js"></script>

</head>
<body ng-app="sampleapp" style="background-color: #E0EEE0">

<a href="#"> Login </a> |
<a href="showdata"> Show Data </a>

<div ng-view align="center" style="border: 1px solid red;">

</div>
</body>
</html>

admin.html

<b>{{ message }}</b>

data-view.html

<b>{{ message }}</b>

2 Answers2

0

Make sure you have added angular-route.js in your index.html file.

Also Please go through the documentation of ui router for the basic setup

forgottofly
  • 2,729
  • 11
  • 51
  • 93
0
var myapp = angular.module('sampleapp', ['ngRoute']);

u need to add ngRoute dependancy also. Because your sampleapp is depend on ngRoute .

<div ng-view></div>

you need to add this also. the partial are loading to this div. put this inside the body.

Kalhan.Toress
  • 21,683
  • 8
  • 68
  • 92