我有一个组件
@Component({
// todo the app-old-selector selector must be removed in the next version
selector: 'app-new-selector,app-old-selector',
templateUrl: './component.html'
})
export class Component {
}
通知开发人员 app-old-selector
已弃用的最佳方式是什么?
最佳答案
也许你可以在你的组件代码中写这样的东西:
import { Component, ElementRef } from '@angular/core'
@Component({
selector: 'app-new-selector,app-old-selector',
templateUrl: './component.html'
})
export class YourComponent {
constructor(elem: ElementRef) {
const tagName = elem.nativeElement.tagName.toLowerCase();
if (tagName === 'app-old-selector') {
console.warn('message');
}
}
}
这意味着我们只是将当前启动的组件的标签名称与表示弃用值的字符串进行比较。如果它们相等 - 这意味着您现在需要通知开发人员。
这是一个有效的 Stackblitz example .在控制台打开的情况下随意运行它。
关于angular - 如何将组件选择器标记为已弃用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54482925/