如何获取angular2组件的父DOM元素引用 [英] How to get the parent DOM element reference of an angular2 component

查看:238
本文介绍了如何获取angular2组件的父DOM元素引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要访问父DOM元素的某些属性,该属性包含要从中获取信息的组件,有没有办法做到这一点?

I need to access to some properties of the parent DOM element which contains the component from where i want to get the info, is there a way to do such thing?

这是我的组件的外观:

import { Component, Input } from "@angular/core";

import "./loadingSpinner.component.css!";

    @Component({
        selector: "loading-spinner",
        template: `
            <div *ngIf="showSpinner" class="loader-directive-wrapper">
                <div class="loader"></div>
            </div>`
    })
    export class LoadingSpinnerComponent {
        @Input() public showSpinner: boolean = false;
    } 

推荐答案

constructor(elementRef:ElementRef) {
  elementRef.nativeElement.parentElement....
}

这篇关于如何获取angular2组件的父DOM元素引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆