自定义指令不适用于Renderer2插入的代码

时间:2020-06-13 18:40:59

标签: angular angular2-directives

我有以下指令

Firstname Lastname
Firstname Middlename Lastname
The cat sat on the mat whilst Firstname Lastname watched in silence.

我有与角度代码一起使用的代码。但是,当我使用Renderer2插入HTML代码时

import {
  Directive,
  HostBinding,
  PLATFORM_ID,
  Inject,
  Input
} from '@angular/core';
import { isPlatformBrowser } from '@angular/common';
import { Router } from '@angular/router';


@Directive({
  selector: 'a[href]'
})
export class ChangeUrlDirective {

  @HostBinding('attr.rel') relAttr = '';
  @HostBinding('attr.target') targetAttr = '';
  @HostBinding('attr.href') hrefAttr = '';
  @Input() href: string;

  constructor(@Inject(PLATFORM_ID) private platformId: string, private router: Router) {}

  ngDoCheck() {
    console.log("hi")
    this.hrefAttr = this.href;

  }




}

我的自定义指令指令不适用于此插入HTML代码。

任何人都知道为什么它不起作用以及如何解决它。

0 个答案:

没有答案
相关问题