angular - Angular7父组件?
问题描述
我正在尝试为我的 webapp 设置安全模型,此安全模型将具有“面板”(节点),每个节点都会有子节点,如果顶级面板没有正确的权限,则应拒绝所有子面板使用权。我现在正在努力的部分是从父元素中获取组件。一旦编译了角度应用程序,代码就不再知道实际的组件?这是一些代码,我应该打那一行this.ParentPanel = e;
,但是这永远不会发生,因为 instaceof 总是返回 false。
import { Component, OnInit, Input, ElementRef} from '@angular/core';
import { TESTControl } from '../testcontrol/testcontrol.component';
@Component({
selector: 'test-panel',
templateUrl: './testpanel.component.html',
styleUrls: ['./testpanel.component.scss']
})
export class TESTPanelComponent implements OnInit {
@Input() disabled = false; // when this is disabled, all children will get disabled as well.
public Children: TESTControl;
public ParentPanel: any;
ngOnInit() {
this.GetParentPanel();
}
constructor(public element: ElementRef) {
}
GetParentPanel() {
// Step up the dom to find the next object that is the parent and a panel (If any)
let stepping = true;
let e = this.element.nativeElement;
let override = 0;
while (stepping) {
e = e.parentElement;
console.log('e:', e);
if (e) {
if (e instanceof TESTPanelComponent) {
stepping = false;
this.ParentPanel = e;
console.log('parent panel set to : ' , this.ParentPanel);
}
} else {
stepping = false;
console.log('no parent');
}
override ++;
if (override >= 1000) { console.log('override. Doesnt exist.'); stepping = false; }
}
}
}
谢谢。
解决方案
推荐阅读
- javascript - 从回调函数渲染 - 打字稿
- c# - 查找 $version$ /assemblyVersion 的 Nuget 运行时值
- tcl - 为什么“parsetcl”不产生输出?
- twilio - Twilio Studio 调查总结在最后
- asp.net-core - Azure、Office 和其他产品中的“切换用户”下拉菜单是否可用于集成到 AAD/B2C Web 应用程序?
- java - Java Web 应用程序 - 下载的文件不可读
- java - 全局设置 Hibernate 访问策略?
- ansible - 如何在 Ansible playbook 中等待 tomcat 服务器启动
- javascript - typeError:无法读取未定义的属性“goBack”
- laravel - Laravel 本地化日期格式(模式)