@@ -6,11 +6,7 @@ The 9.0.0 release of Angular is here! This is a major release that spans the ent
66
77Angular 的 9.0.0 版本发布了!这是一个跨平台的主版本,包括框架、Angular Material 和 CLI。这个版本默认会把应用程序切换到 [ Ivy] ( https://angular.cn/guide/ivy ) 编译器和运行时,并改进了组件测试方法。
88
9- <figure >
10-
11- ![ ] ( https://miro.medium.com/max/3200/0*4tkqVWVOl0dGjbO9 )
12-
13- </figure >
9+ ![ Ivy] ( ./.Angular-9-release_images/ivy.png )
1410
1511This is one of the biggest updates to Angular we’ve made in the past 3 years, and we’re excited for all of the ways it empowers developers to build better applications and contribute to the Angular ecosystem.
1612
@@ -28,13 +24,13 @@ First, update to the latest version of 8
2824
2925首先,更新到 8 的最新版本
3026
31- < pre >< span > ng update @angular/cli@8 @angular/core@8</ span ></ pre >
27+ ` ng update @angular/cli@8 @angular/core@8 `
3228
3329Then, update to 9
3430
3531然后,升级到 9
3632
37- < pre >< span > ng update @angular/cli @angular/core</ span ></ pre >
33+ ` ng update @angular/cli @angular/core `
3834
3935To review the key changes with this update, including deprecated APIs, see [ Updating to Angular version 9] ( https://v9.angular.io/guide/updating-to-version-9 ) in the Angular documentation.
4036
@@ -110,9 +106,7 @@ With these improvements, small apps and large apps can see the most dramatic siz
110106
111107<figure >
112108
113- ![ ] ( https://miro.medium.com/max/3200/0*7dSxEASiMazbMt7N )
114-
115- <figcaption >Small apps could see around a 30% decrease in bundle size, large apps will see a 25–40% decrease, and medium apps decrease minimally.</figcaption >
109+ ![ 打包尺寸] ( ./.Angular-9-release_images/bundle-size.png )
116110
117111<figcaption >小型应用程序的发布包体积可减少约 30%,大型应用程序的发布包体积可减少 25–40%,而中型应用程序的发布包受益最少。</figcaption >
118112
@@ -160,7 +154,7 @@ Ivy 为你提供了更多调试应用的工具。当我使用 Ivy 运行时在
160154
161155<figure >
162156
163- ![ ] ( https://miro.medium.com/max/1164/0*RB_jqf6GCX-Ewq5V )
157+ ![ applyChanges ] ( ./.Angular-9-release_images/applyChanges.png )
164158
165159</figure >
166160
@@ -170,7 +164,7 @@ Ivy 还改进了用于调试问题的调用栈跟踪,比如 `ExpressionChanged
170164
171165<figure >
172166
173- ![ ] ( https://miro.medium.com/max/3192/0*I4qPrPIXJi2yUj99 )
167+ ![ ExpressionChangedAfterItHasBeenCheckedError ] ( ./.Angular-9-release_images/ExpressionChangedAfterItHasBeenCheckedError.png )
174168
175169</figure >
176170
@@ -180,7 +174,7 @@ With Ivy, you see a more useful stack trace that allows you to jump directly to
180174
181175<figure >
182176
183- ![ ] ( https://miro.medium.com/max/3036/0*QPhLwDCufQOOhRVo )
177+ ![ Stack Trace ] ( ./.Angular-9-release_images/stack-trace.png )
184178
185179</figure >
186180
@@ -190,7 +184,7 @@ For example, if you click on `AppComponent_Template` in the stack trace above, y
190184
191185<figure >
192186
193- ![ ] ( https://miro.medium.com/max/3200/0*69sx5aAdQyJoGbqv )
187+ ![ AppComponent Template ] ( ./.Angular-9-release_images/AppComponent_Template.png )
194188
195189</figure >
196190
@@ -210,17 +204,26 @@ Consider the following template and component snippets:
210204
211205考虑下面的模板和组件片段:
212206
213- <figure >
214-
215- <div ><iframe src =" https://blog.angular.io/media/eebd878c8eeb1f4a66e4b5048a2a1a70 " allowfullscreen =" " frameborder =" 0 " height =" 80 " width =" 680 " title =" snippet.html " scrolling =" auto " ></iframe ></div >
216-
217- </figure >
218-
219- <figure >
220-
221- <div ><iframe src =" https://blog.angular.io/media/5e3da6a82d530d7d665f8d76d6a6452b " allowfullscreen =" " frameborder =" 0 " height =" 351 " width =" 680 " title =" snippet.ts " scrolling =" auto " ></iframe ></div >
222-
223- </figure >
207+ ``` html
208+ <my-component style =" color :red ;" [style.color] =" myColor" [style] =" {color: myOtherColor}" myDirective ></div >
209+ ```
210+
211+ ``` typescript
212+ @Component ({
213+ host: {
214+ style: " color:blue"
215+ },...
216+ })
217+ ...
218+
219+ @Directive ({
220+ host: {
221+ style: " color:black" ,
222+ " [style.color]" : " property"
223+ },...
224+ })
225+ ...
226+ ```
224227
225228Previously, whichever binding was evaluated last would win, and this could depend on the timing of changes to these expressions. If ` myColor ` and ` myOtherColor ` both were undefined, the static ‘red’ style would be ignored.
226229
@@ -242,11 +245,11 @@ As a side effect of the styling refactoring, you can now also bind to [CSS custo
242245
243246作为样式重构的一个额外收获,你现在也可以绑定 [ CSS 自定义属性] ( https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties ) (也叫 CSS 变量)了。
244247
245- < figure >
246-
247- <div >< iframe src = " https://blog.angular.io/media/66b492e125b315183ace725b5de7e2c6 " allowfullscreen = " " frameborder = " 0 " height = " 109 " width = " 680 " title = " custom-properties.html " scrolling = " auto " ></ iframe ></ div >
248-
249- </ figure >
248+ ``` html
249+ < div [style. -- main-border-color] = " '#CCC' " >
250+ <p style = " border : 1 px solid var ( --main-border-color ) " >hi</ p >
251+ </ div >
252+ ```
250253
251254# Improved type checking
252255
@@ -284,21 +287,13 @@ In version 8 or View Engine, a typical compiler error would look like the follow
284287
285288在版本 8 或 View Engine 中,典型的编译器错误如下所示:
286289
287- <figure >
288-
289- ![ ] ( https://miro.medium.com/max/2052/0*9MynS6_WDBlGkYqN )
290-
291- </figure >
290+ ![ View Engine] ( ./.Angular-9-release_images/ViewEngine.png )
292291
293292In version 9 with Ivy, the same error looks like:
294293
295294在使用 Ivy 的 9 版本中,同样的错误如下:
296295
297- <figure >
298-
299- ![ ] ( https://miro.medium.com/max/2056/0*Ag3LaCG6UVxNppq4 )
300-
301- </figure >
296+ ![ Ivy] ( ./.Angular-9-release_images/IvyEngine.png )
302297
303298# Improved build times, enabling Ahead-of-Time compiler on by default
304299
@@ -400,21 +395,35 @@ Here’s an example test before harnesses:
400395
401396这是一个在使用组件挽具之前的一个测试范例:
402397
403- <figure >
404-
405- <div ><iframe src =" https://blog.angular.io/media/ecba92926e72f27a8848131c34f1f142 " allowfullscreen =" " frameborder =" 0 " height =" 351 " width =" 680 " title =" test-before.ts " scrolling =" auto " ></iframe ></div >
406-
407- </figure >
398+ ``` typescript
399+ it (" should switch to bug report template" , async () => {
400+ expect (fixture .debugElement .query (" bug-report-form" )).toBeNull ();
401+ const selectTrigger = fixture .debugElement .query (
402+ By .css (" .mat-select-trigger" )
403+ );
404+ selectTrigger .triggerEventHandler (" click" , {});
405+ fixture .detectChanges ();
406+ await fixture .whenStable ();
407+ const options = document .querySelectorAll (" .mat-select-panel mat-option" );
408+ options [1 ].click (); // Click the second option, "Bug".
409+ fixture .detectChanges ();
410+ await fixture .whenStable ();
411+ expect (fixture .debugElement .query (" bug-report-form" )).not .toBeNull ();
412+ });
413+ ```
408414
409415And the same test with harnesses:
410416
411417而用组件挽具做同样的测试如下:
412418
413- <figure >
414-
415- <div ><iframe src =" https://blog.angular.io/media/eaaaaa0a220d9ae0e5e7ad4a410030ba " allowfullscreen =" " frameborder =" 0 " height =" 175 " width =" 680 " title =" test-after.ts " scrolling =" auto " ></iframe ></div >
416-
417- </figure >
419+ ``` typescript
420+ it (" should switch to bug report template" , async () => {
421+ expect (fixture .debugElement .query (" bug-report-form" )).toBeNull ();
422+ const select = await loader .getHarness (MatSelect );
423+ await select .clickOptions ({ text: " Bug" });
424+ expect (fixture .debugElement .query (" bug-report-form" )).not .toBeNull ();
425+ });
426+ ```
418427
419428Learn more about [ Material’s component harnesses] ( https://v9.material.angular.io/guide/using-component-harnesses ) or [ building your own] ( https://v9.material.angular.io/cdk/testing/overview ) with the CDK.
420429
@@ -442,7 +451,7 @@ You can now include capabilities from YouTube and Google Maps in your applicatio
442451
443452<figure >
444453
445- ![ ] ( https://miro.medium.com/max/1280/1*EFcVVFKZKOshNNpJd9ot6g.gif )
454+ ![ Language Service ] ( ./.Angular-9-release_images/language-service.png )
446455
447456<figcaption >转到定义(Go to definition)和改进的语言服务演示</figcaption >
448457
0 commit comments