Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

docs($rootScope.Scope): reinsert lost example #12167

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/ng/rootScope.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,24 @@ function $RootScopeProvider() {
* compiled HTML template is executed.)
*
* Here is a simple scope snippet to show how you can interact with the scope.
* ```html
* <file src="./test/ng/rootScopeSpec.js" tag="docs1" />
* ```js
var scope = $rootScope.$new();
scope.salutation = 'Hello';
scope.name = 'World';

expect(scope.greeting).toEqual(undefined);

scope.$watch('name', function() {
scope.greeting = scope.salutation + ' ' + scope.name + '!';
}); // initialize the watch

expect(scope.greeting).toEqual(undefined);
scope.name = 'Misko';
// still old value, since watches have not been called yet
expect(scope.greeting).toEqual(undefined);

scope.$digest(); // fire all the watches
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably change this to scope.$apply(), since the use of $digest is basically not recommened anywhere in the docs.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't disagree regarding $digest not being recommended, but changing the example is not quite the scope of this request. This example was accidentally removed so I am just putting it back. This sample comes directly from the unit tests. All the examples on this page use $digest; none of them use $apply. The notes do indicate that $digest is not recommended, but similar notes regarding 'better practices' exist throughout the documentation. If you would like to file an issue to have the examples all changed to $apply, I think that would be great and hopefully someone can pick it up. Thanks!

expect(scope.greeting).toEqual('Hello Misko!');
* ```
*
* # Inheritance
Expand Down