0

Following is my angular code.I searched a lot for the solution for the error,the solution mentioned is include ['ngroute'],I have included but still the error is not being solved.

Below is the code:

Index.html

 <!DOCTYPE html>
 <html ng-app="myapp">
<head>
    <script type="text/javascript" src="angular.min.js"></script>
    <script type="text/javascript" src="angular-route.min.js"></script>
    <script type="text/javascript" src="controller.js"></script>
</head>
<body>
    <h1>Amail</h1>
    <div ng-view></div>
</body>
  </html>

controller.js

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

  function emailRouteConfig ($routeProvider,$locationProvider) {
   $locationProvider.html5mode(true);
   $routeProvider.
   when('/',{
    controller:'ListController',
    templateUrl:'list.html'
   }).
   when('/view/:id',{
    controller:'DetailController',
    templateUrl:'detail.html'
   }).
   otherwise({
    redirectTo:'/'
   });
   }

   aMailservices.config(emailRouteConfig);


   messages = [{
        id: 0, sender: '[email protected]', subject: 'Hi there, old friend',
        date: 'Dec 7, 2013 12:32:00', recipients: ['[email protected]'],
        message: 'Hey, we should get together for lunch sometime and catch up.'
        +'There are many things we should collaborate on this year.'
        }, {
        id: 1, sender: '[email protected]',
        subject: 'Where did you leave my laptop?',
        date: 'Dec 7, 2013 8:15:12', recipients: ['[email protected]'],
            message: 'I thought you were going to put it in my desk drawer.'
        +'But it does not seem to be there.'
        }, {
        id: 2, sender: '[email protected]', subject: 'Lost python',
        date: 'Dec 6, 2013 20:35:02', recipients: ['[email protected]'],
        message: "Nobody panic, but my pet python is missing from her cage."
        +"She doesn't move too fast, so just call me if you see her."
        } ];

    function ListController($scope){
    $scope.messages=messages;
          }

     function DetailController($scope,$routeParams){
      $scope.message=messages[$routeParams.id];
         }

list.html

 <table>
<tr>
    <td><strong>Sender</strong></td>
    <td><strong>Subject</strong></td>
    <td><strong>Date</strong></td>
</tr>   
<tr ng-repeat='message in messages'>
        <td>{{message.sender}}</td>
        <td><a href="#/view/{{message.id}}"></a></td>
        <td>{{message.date}}</td>
</tr>

detail.html

<div><strong>Subject:</strong>{{message.subject}}</div>
<div><strong>Sender:</strong>{{message.sender}}</div>
<div><strong>Date:</strong>{{message.date}}</div>
<div>
<strong>To:</strong>
<span ng-repeat="recipient in message.recipients">{{recipient}}</span>
</div>
<div>{{message.message}}</div>
<a href="#/">Back to message list</a>
3
  • 2
    What is the error, exactly? Commented Jan 10, 2014 at 18:44
  • He's likely getting a "Angularjs injector modulerr" when he tries to use $routeParams in his controller. Commented Jan 10, 2014 at 19:06
  • @Beterraba The exact error is Uncaught Error: [$injector:modulerr] errors.angularjs.org/1.2.6/$injector/……t%2520Brothers%2Fangular%2Fegs%2Fchap2%2Femail%2Fangular.min.js%3A17%3A178) Commented Jan 11, 2014 at 3:42

1 Answer 1

1

I would advise you add your controllers to the module, otherwise they won't pick up on the $routeParams. The dependency was injected into your module; if your controllers aren't added to the module, then they won't be able to take advantage of the dependency injected into the module.

Do the following:

angular.module("myapp",['ngRoute']).config(function($routeProvider,$locationProvider) {})
.controller('DetailController', function($scope,$routeParams){});
Sign up to request clarification or add additional context in comments.

1 Comment

Hi @C Fairweather I did the following changes in my code.I added the below lines aMailservices.controller('ListController',function($scope){ $scope.messages=messages; }); aMailservices.controller('DetailController',function($scope,$routeParams){ $scope.message=messages[$routeParams.id]; }); Still i m getting the error.Dont know what I m doing wrong

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.