0

I am triyng to reach a simple app that return result from a MongoDB I am getting this error in the console;

Uncaught TypeError: Cannot read property 'controller' of undefined at model.js:8

'use strict';

var mid = angular.module('mid', [
  'ngRoute'
]).


    mid.controller('pageCtrl', function($scope, $http){ <------- This line
      $scope.pages = [];

      $http({
        method: 'GET',
        url: 'http://127.0.0.1/pages'
      })
        .then(function(pages) {
          $scope.pages = pages.data;
       })
        .catch(function(errRes) {
          // Handle errRess
      });
    });

What am I doing wrong?

2
  • remove .(dot) and use semicolon OR remove mid. you need to go like Object chaining. Commented Jan 19, 2017 at 4:16
  • If you're going to opt to not use ;s then do it always unless necessary or use them. Don't do both. Commented Jan 19, 2017 at 4:29

1 Answer 1

2

Remove the . after declaring module

var mid = angular.module('mid', [
  'ngRoute'
])

DEMO

'use strict';

var mid = angular.module('mid', [])
mid.controller('pageCtrl', function($scope, $http){ 
      $scope.display = "test";
      
 });
<!DOCTYPE html>
<html ng-app="mid">
<head>
  <script src="https://code.angularjs.org/1.2.1/angular.js"></script>
  <link rel="stylesheet" href="style.css" />
 </head>
<body ng-controller="pageCtrl">
 
{{display}}
</body>
</html>

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

4 Comments

Close, but they need to complete the statement with a ; or remove the mid. for your answer.
@ChiefTwoPencils no need
Thank you removing the dot did it. will accept in 10
Ewe. Staying consistent would be nice.

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.