0

I can't find the meaning of the first $scope in this example:

app.controller('HelloController', function($scope) {
  $scope.message = 'Hello World!';
});

I know that this is JavaScript and it is supposed to be a parameter for the function but I don't understand what sort of parameter it sets.

Can anyone help?

Thanks!

3
  • 2
    Try the manual docs.angularjs.org/guide/scope. Also go through the tutorial on the documentation site ... do each step, well wortth the time Commented Jan 28, 2015 at 19:29
  • 3
    I'm voting to close this question as off-topic because the question is explained by angularjs documentation. Commented Jan 28, 2015 at 19:31
  • Actually I have read the docs several times and stil can't find an answer to my question. Commented Jan 28, 2015 at 19:36

2 Answers 2

3

The $scope parameter is being injected into your controller and acts as the "glue" between your controller and view. So, in your example you would be able to referrence the $scope.message property from your html like this:

<div ng-controller="HelloController">
   {{message}}
</div>

I would check out the docs and Angular communities on google+. Good resources to get started.

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

1 Comment

Here is a great explanation of scope from the Angular docs: docs.angularjs.org/guide/scope
2

A $scope is a JavaScript object which is used to communicate between controller and view. Basically, $scope binds a view (DOM element) to the model and functions defined in a controller. enter image description here

see more at https://docs.angularjs.org/guide/scope

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.