0

I am beginner in AngularJS, so I try to run basic code. However, this simple code does not work in a way I want. The html code is the following:

<!DOCTYPE html>
<html ng-app> 
<head>
  <script src="js/angular.min.js"></script>
  <script> 
    function MyFirstCtrl($scope) { 
      var employees = ['Jon Doe', 'Abe Lincoln', 'Hugh Grant']; 
      $scope.ourEmployees = employees;
    } 
  </script>
</head> 
<body ng-controller='MyFirstCtrl'> 
  <h2>Number of Employees: {{ourEmployees.length}}</h2> 
</body>
</html>

I'd expect that the correct result is Number of Employees: 3 Instead of this, the browser (both Firefox and Edge) shows the following: Number of Employees: {{ourEmployees.length}}. Since other simple codes did work, the problem is surely not the reference to the angular.min.js file.

Thanks in advance.

1
  • Please open the browser's JavaScript console and look for the error messages. They will tell you what's wrong. Commented Sep 15, 2015 at 6:56

1 Answer 1

2

Global controller functions are no longer supported by default in 1.3. You should adopt module approach.

$controller will no longer look for controllers on window. The old behavior of looking on window for controllers was originally intended for use in examples, demos, and toy apps. We found that allowing global controller functions encouraged poor practices, so we resolved to disable this behavior by default.

See example snippet :

angular.module('myApp', [])
       .controller('MyFirstCtrl', function ($scope) {

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

Comments

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.