Laurent-514
Laurent-514

Reputation: 621

AngularJS function - $Scope

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!

Upvotes: 0

Views: 57

Answers (2)

Nisham Mahsin
Nisham Mahsin

Reputation: 1399

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

Upvotes: 2

Cognitronic
Cognitronic

Reputation: 1436

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.

Upvotes: 3

Related Questions