【问题标题】:Combine two directives together将两个指令组合在一起
【发布时间】:2016-09-14 21:14:17
【问题描述】:

我想通过 formControlName 指令将给定的模型数据与我自己的指令一起使用。

<input type="text"
       formControlName="endDate"
       my-directive>

有没有办法访问指令中的 formControl-value?在组件中使用 ControlValueAccessors 非常容易...

【问题讨论】:

  • “一起”是什么意思。如果多个指令匹配,则全部应用。
  • 你到底在问什么?您想将endDate 传递给指令以在逻辑中使用它。
  • 使用my-directive,如何访问formControlName?

标签: javascript html angular


【解决方案1】:

只需创建一个匹配的输入,你就会得到传递的值:

@Directive({
  selector: '[my-directive]'
})
class MyDirective {
  @Input() formControlName:String;

  ngOnChanges() {
    console.log(this.formControlName);
  }
}

【讨论】:

    猜你喜欢
    • 2017-05-27
    • 1970-01-01
    • 1970-01-01
    • 2013-09-05
    • 1970-01-01
    • 1970-01-01
    • 2011-07-22
    • 2015-09-08
    • 1970-01-01
    相关资源
    最近更新 更多