V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
wly19960911
V2EX  ›  问与答

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

  •  
  •   wly19960911 · 2019-01-04 15:47:51 +08:00 · 1362 次点击
    这是一个创建于 1929 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我简略搜索了下,实现原理好像并不是和 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,
    }
    
    
    2 条回复    2019-01-04 16:19:16 +08:00
    wly19960911
        1
    wly19960911  
    OP
       2019-01-04 16:09:24 +08:00
    https://stackoverflow.com/questions/44982328/how-does-angular-handle-binding-for-class-example-true

    确定了,这种解析方式完全是另外一套机制,固定的解析方式,而不是能自由写的。我正好也想试试和题主那样的方式,查了下源码完全没头脑了,刚刚才查到
    wly19960911
        2
    wly19960911  
    OP
       2019-01-04 16:19:16 +08:00
    最后我只能说,这个 TM 根本不是指令...这个是一套单独的解析。难怪查指令大多都是 ngStyle 的内容了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3289 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 13:56 · PVG 21:56 · LAX 06:56 · JFK 09:56
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.