2016年4月29日 星期五

Angular 2.0.0-beta.17 breaking changes

Angular 2 更該至 beta.17 後,發生 warning:
Template parse warnings:
"#" inside of expressions is deprecated. Use "Let" instead! ....

似乎有做小改版,趕緊來看看 release note ,內容如下:

Before:
  • Outside of ngFor, a #... meant a reference.
  • Inside of ngFor, it meant a local variable.
This was pattern was confusing.

After:
  • <template #abc> now defines a reference to a TemplateRef, instead of an input variable used inside of the template.
  • Inside of structural directives that declare local variables, such as *ngFor, usage of #... is deprecated. Use let instead.
    • <div *ngFor="#item of items"> now becomes <div *ngFor="let item of items">
  • var-... is deprecated.
    • use # or a ref- outside of *ngFor
    • for ngFor, use the syntax: <template ngFor let-... [ngForOf]="...">

簡單說 # 的用法會讓人混淆,
搭配 ngFor 使用,是定義迴圈內的私有變數,
但放在 dom element attribute 位置時,指的又是此 dom element 的參考,

為避免混淆,所以 ngFor 改用 let 宣告私有變數,
就是這麼一回事,
了解前因後果後,
就不會想要翻桌,
狂罵改個屁呀!

沒有留言:

張貼留言