I seem to be having trouble applying height/width to a child component in angular. Can someone take a look and point out where I may have gone wrong?
app.component.html
<app-child [width]="10" [height]="10"></app-child>
.child.ts
import { Component, OnInit, Input, ViewEncapsulation, Renderer2, ElementRef } from '@angular/core';
@Component({
encapsulation: ViewEncapsulation.None,
selector: 'app-child',
templateUrl: './child.component.html',
styleUrls: ['./child.component.css']
})
export class ChildComponent {
constructor(private renderer: Renderer2, private elRef: ElementRef) { }
@Input() width
@Input() height
ngAfterViewInit() {
this.renderer.setStyle(this.elRef.nativeElement, 'height', this.height + "%");
this.renderer.setStyle(this.elRef.nativeElement, 'width', this.width + "%");
}
}
.child.html
<div class="wrapper" [style.width.%]="width" [style.height.%]="height">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
Issues :
app-child component still takes full width and hight it should be 10% div inside app-child taking correct width but height is still 100%
Example link