Try to use your code in ngAfterViewInit event.
And you need to use parentNode property instead parent
export class App {
el: ElementRef;
constructor(el: ElementRef){
this.el = el;
},
ngAfterViewInit() {
const hostElem = this.el.nativeElement;
console.log(hostElem.children);
console.log(hostElem.parentNode);
}
}
Related Contents:
- How can I select an element in a component template?
- How should I use the new static option for @ViewChild in Angular 8?
- angular-cli server – how to specify default port
- Error:Unable to locate adb within SDK in Android Studio
- Difference between interfaces and classes in Typescript
- How to clear form after submit in Angular 2?
- Use object literal as TypeScript enum values
- Angular 2 – Redirect to an external URL and open in a new tab
- Angular2 router (@angular/router), how to set default route?
- Angular 4 checkbox change value
- How to validate white spaces/empty spaces? [Angular 2]
- Angular Material and Jasmine : ” No provider for InjectionToken MdDialogData! “
- How to set dynamic id in *ngFor?
- Attempt to use a destroyed view: detectChanges
- Programmatically select mat-tab in Angular 2 material using mat-tab-group
- Pass variable to custom component
- Null coalescing operator angular 2
- TSLint Error “Exceeds maximum line length of 120”
- Angular4 Application running issues in IE11
- CanActivate vs. CanActivateChild with component-less routes
- How to bind event listener for rendered elements in Angular 2?
- Angular4 Exception: Can’t bind to ‘ngClass’ since it isn’t a known property of ‘input’
- Service: No provider for Renderer2
- Error: “Encountered undefined provider! Usually this means you have a circular dependencies”
- Set Form to Pristine without clearing data
- No provider for ChildrenOutletContexts (injectionError)
- How can I add a class to an element on hover?
- HttpClient POST request using x-www-form-urlencoded
- How to store token in Local or Session Storage in Angular 2?
- Sort an array of objects in typescript?
- Available yeoman generator for Angular 2 [closed]
- Could not use Observable.of in RxJs 6 and Angular 6
- Role of imports / exports in Angular 2+ ngModule
- Why use “?” operator in template binding?
- Getting reference to child component in parent component [duplicate]
- Angular 5 service failing to pass unit tests with (NullInjectorError: No provider for HttpClient!)
- What is the difference between testbed.get and inject in Angular 2/Jasmine testing?
- Angular 2 Form “Cannot find control with path”
- Hybrid App – Ionic vs NativeScript
- How to handle error in a Resolver
- How to send “Cookie” in request header for all the requests in Angular2?
- Angular 2 routing redirect to with child routes
- How to get reference of the component associated with ElementRef in Angular 2
- How can I access an activated child route’s data from the parent route’s component?
- Angular service decorator providedIn root effect on lazy loading
- How do I build with watch enabled using angular-cli?
- Deploy single page application Angular: 404 Not Found nginx
- Stripping all comments and console.logs with ng build –prod, possible?
- Pass different context to ngIf
- How to get element’s width/height within directives and component?