Я не могу применить высоту / ширину к дочернему компоненту в angular. Пожалуйста, посмотрите и дайте мне знать, где и что я делаю неправильно
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 по-прежнему занимает всю ширину, а высота его должна составлять 10%. app-child принимает правильную ширину, но высота все еще составляет 100%
Пример ссылки
https://stackblitz.com/edit/angular-qgobau