3

While i am trying to click on show its not showing any thing, i have wasted lot of time on this, but no luck can some one help.

Files....

  1. app.js
  2. controller.js
  3. index.html
  4. show.html

index.html

<html ng-app='Java4sApp'>
<head>
    <title>Angular Js Tutorials _ Java4s</title>
    <script type="text/javascript" src="angular.min.js"></script>
    <script type="text/javascript" src="app.js"></script>
    <script type="text/javascript" src="controllers.js"></script>
    </head>
<body>

<div ng-controller='Java4sController'>



            Settings :
            <a href="#add">Add Details</a> | <a href="#show">Show Details</a> 

            <div ng-view></div>

</div>

</body>
</html>

show.html

<html ng-app='Java4sApp'>
<head>
    <title>Angular Js Tutorials _ Java4s</title>
    <script type="text/javascript" src="angular.min.js"></script>
    <script type="text/javascript" src="app.js"></script>
    <script type="text/javascript" src="controllers.js"></script>
</head>
<body>

<div ng-controller='Java4sController'>


            <input type="text" ng-model="myModel" />

            <ul>
                <li ng-repeat='person in people | filter:myModel'>{{person.name}}</li>
            </ul>


</div>

</body>
</html>

controller.js

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

    $routeProvider.
      when('/add', {
        controller: 'Java4sController',
        templateUrl: '/add.html'
    }).
      when('/show', {
        controller: 'Java4sController',
        templateUrl: '/show.html'
    }).
      otherwise({
        redirectTo: '/index.html'
      });
}]);

app.controller("Java4sController",function($scope){

        $scope.people = [
            {name: 'Siva', city: 'Cary'},
            {name: 'Teja', city: 'Raleigh'},
            {name: 'Reddy', city: 'Durham'},
            {name: 'Venky', city: 'Denver'},
            {name: 'Arun', city: 'Texas'}
    ];

});

app.js

var app = angular.module("Java4sApp",[]);

Thank you.

1
  • Do you get any error in your console? Commented Mar 27, 2014 at 4:33

1 Answer 1

8

You need to inject the 'ngRoute' dependency when you are creating your module.

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

Also make sure you obtain Angular routing js and add a reference to it, in your index.html

<script src="scripts/angular-route.js"></script>

A good example can be found here

Please let me know if this doesn't fix your problem

UPDATE

This is a simple plunker that shows AngularJS Routing

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

9 Comments

Hi Thara, added, but no luck, if possible can you connect my system.
In some examples, they did not added ngRoute, its bit confusing me Thara.
I see quite a few problems in your code. 1. I cannot see you have used ngView 2. You are attempting to share multiple controllers (which is bad) Let me put up a plunker n see
Okay, this seems to be a good pluker for you: plnkr.co/edit/wUhAGG?p=preview . Hope this helps :).
How did you go with fixing your problem. If you found my answer is correct and helpful could please mark this as the answer as explained here meta.stackexchange.com/a/5235
|

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.