Angular指令覆盖指令
创始人
2024-10-30 22:30:52
0

在Angular中,指令覆盖指令的解决方法有两种:使用@Directive()装饰器的{​​​​​​​provideIn: 'root'}选项和使用{​​​​​​​provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => MyCustomControlDirective), multi: true}选项。

下面是两种解决方法的代码示例:

  1. 使用@Directive()装饰器的{​​​​​​​provideIn: 'root'}选项:
import {​​​​​​​ Directive }​​​​​​​ from '@angular/core';

@Directive({​​​​​​​
  selector: '[appMyCustomDirective]',
  provideIn: 'root'
}​​​​​​​)
export class MyCustomDirective {​​​​​​​
  // 指令逻辑...
}​​​​​​​
  1. 使用{​​​​​​​provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => MyCustomControlDirective), multi: true}选项:
import {​​​​​​​ Directive, forwardRef }​​​​​​​ from '@angular/core';
import {​​​​​​​ NG_VALUE_ACCESSOR }​​​​​​​ from '@angular/forms';

@Directive({​​​​​​​
  selector: '[appMyCustomControl]',
  providers: [
    {​​​​​​​ provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => MyCustomControlDirective), multi: true }
  ]
}​​​​​​​)
export class MyCustomControlDirective {​​​​​​​
  // 指令逻辑...
}​​​​​​​

这两种方法都可以用来解决指令覆盖指令的问题,具体使用哪种方法取决于你的需求和场景。

相关内容

热门资讯

今年以来!aa poker透视... 今年以来!aa poker透视软件,德普之星透视软件免费入口官网,指南教程(的确有挂)1)德普之星透...
记者获悉!wepoker辅助工... 记者获悉!wepoker辅助工具,wepoker有没有插件,讲义教程(有挂技巧)1、打开软件启动之后...
2026版软件!智星菠萝透视,... 2026版软件!智星菠萝透视,wpk安卓下载辅助,课程教程(真是有挂)1、wpk安卓下载辅助免费辅助...
随着!poker world辅... 随着!poker world辅助,wepoker破解工具,讲义教程(讲解有挂)1、点击下载安装,we...
为切实保障!sohoo辅助,佛... 为切实保障!sohoo辅助,佛手大菠萝有挂吗,练习教程(有挂技巧)运佛手大菠萝有挂吗辅助工具,进入游...
有消息称!hhpoker软件可... 有消息称!hhpoker软件可以玩吗,aa poker透视软件,方针教程(的确有挂)1、玩家可以在h...
据了解!hh poker软件,... 据了解!hh poker软件,hhpoker免费透视脚本,讲义教程(有挂实锤)小薇(辅助器软件下载)...
2026版规律!wepoker... 2026版规律!wepoker手机助手,wepoker怎么买辅助,教程书教程(真的有挂)1、wepo...
更值得关注的是!来玩app破解... 更值得关注的是!来玩app破解版,约局吧作弊脚本,步骤教程(有挂秘笈)1、操作简单,无需约局吧作弊脚...
相较于以往!aapoker辅助... 相较于以往!aapoker辅助器是真的吗,aapoker脚本,手段教程(有挂神器)1、aapoker...