From bde4cd7982722d0849b78c41f5c7b57e0fe6b41d Mon Sep 17 00:00:00 2001 From: JiaLiPassion Date: Sat, 7 Dec 2019 23:30:53 +0900 Subject: [PATCH] docs: add documentation of NgZone with zone.js (#34295) PR Close #34295 --- .pullapprove.yml | 3 +- aio/content/guide/zone.md | 418 ++++++++++++++++++++++++++++++++++++ aio/content/navigation.json | 5 + 3 files changed, 425 insertions(+), 1 deletion(-) create mode 100644 aio/content/guide/zone.md diff --git a/.pullapprove.yml b/.pullapprove.yml index ead89ac1cc..fd3b23eea0 100644 --- a/.pullapprove.yml +++ b/.pullapprove.yml @@ -643,7 +643,8 @@ groups: conditions: - > contains_any_globs(files, [ - 'packages/zone.js/**' + 'packages/zone.js/**', + 'aio/content/guide/zone.md' ]) reviewers: users: diff --git a/aio/content/guide/zone.md b/aio/content/guide/zone.md new file mode 100644 index 0000000000..13c8c2fbb9 --- /dev/null +++ b/aio/content/guide/zone.md @@ -0,0 +1,418 @@ +# NgZone + +A zone is an execution context that persists across async tasks. You can think of it as [thread-local storage](http://en.wikipedia.org/wiki/Thread-local_storage) for JavaScript VMs. +This guide describes how to use Angular's NgZone to automatically detect changes in the component to update HTML. + +## Fundamentals of change detection + +To understand the benefits of `NgZone`, it is important to have a clear grasp of what change detection is and how it works. + +### Displaying and updating data in Angular + +In Angular, you can [display data](guide/displaying-data) by binding controls in an HTML template to the properties of an Angular component. + + + +In addition, you can bind DOM events to a method of an Angular component. In such methods, you can also update a property of the Angular component, which updates the corresponding data displayed in the template. + + + +In both of the above examples, the component's code updates only the property of the component. +However, the HTML is also updated automatically. +This guide describes how and when Angular renders the HTML based on the data from the Angular component. + + +### Detecting changes with plain JavaScript + +To clarify how changes are detected and values updated, consider the following code written in plain JavaScript. + +```javascript + +
+