0

I am still new on angularjs and have a question: How does the controller still know which module it registerred to on code snippet below (found on the Angular official document): JS

 angular.module('App', []);
    function Ctrl($scope) {
      $scope.val = 1234.56789;
    }

Html something like:

<html ng-app="App">
<body>
<div ng-controller="Ctrl">
 ........
</div>
</body>
</html>

I suspect there is something to do with bootstrap time and $scope available globally???

Thank you very much

1 Answer 1

1

If you want to define a controller in a module, call the controller method on the module:

var module = angular.module('App', []);

module.controller('Ctrl', function ($scope) {
   $scope.val = 1234.56789;
});
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Josheph, that is what we've already done in our project. But supprising ly this code snippet WORKS and there are a lot in Angular Official Documentation without further explanation. Here is an example:docs.angularjs.org/api/ng.filter:number. You can see its plnkr
it works because it defines a simple controller in a global window context... but in a real world, I suppose you can't find an application which is this simple

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.