angular 的 [style.width] 这种指令的绑定原理是什么?

2019-01-04 15:47:51 +08:00
 wly19960911

我简略搜索了下,实现原理好像并不是和 ngStyle 这种类似。在源码中看到一个枚举类型,这个是不是指的是 property (类似 ngStyle )和 [style.rule] 完全是两套机制?

文件是 template_ast.ts

export const enum PropertyBindingType {
  // A normal binding to a property (e.g. `[property]="expression"`).
  Property,
  // A binding to an element attribute (e.g. `[attr.name]="expression"`).
  Attribute,
  // A binding to a CSS class (e.g. `[class.name]="condition"`).
  Class,
  // A binding to a style rule (e.g. `[style.rule]="expression"`).
  Style,
  // A binding to an animation reference (e.g. `[animate.key]="expression"`).
  Animation,
}

1370 次点击
所在节点    问与答
2 条回复
wly19960911
2019-01-04 16:09:24 +08:00
https://stackoverflow.com/questions/44982328/how-does-angular-handle-binding-for-class-example-true

确定了,这种解析方式完全是另外一套机制,固定的解析方式,而不是能自由写的。我正好也想试试和题主那样的方式,查了下源码完全没头脑了,刚刚才查到
wly19960911
2019-01-04 16:19:16 +08:00
最后我只能说,这个 TM 根本不是指令...这个是一套单独的解析。难怪查指令大多都是 ngStyle 的内容了

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/523902

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX