Более гибкое решение для создания элементов и связывания событий ( source )
// creating a dynamic element (container div)
var $div = $("", {id: 'myid1', class: 'myclass'});
//creating a dynamic button
var $btn = $("
1
задан Strider 28 March 2019 в 00:08
поделиться
Высота панели уведомлений может быть получена с помощью средства получения свойств. Когда эта высота изменяется, вызовите ChangeDetectorRef.detectChanges
, чтобы избежать исключения, которое возникнет, когда высота будет применена к элементу div
.
@ViewChild("notificationBar") private notificationBarRef: ElementRef<HTMLElement>;
private _notificationBarHeight: number = null;
public get notificationBarHeight(): number {
const height = this.notificationBarRef ? this.notificationBarRef.nativeElement.offsetHeight : null;
if (Math.abs(height - this._notificationBarHeight) > 0.1) {
this._notificationBarHeight = height;
this.changeDetectorRef.detectChanges();
}
return this._notificationBarHeight;
}
В шаблоне установите высоту элемента div
в пикселях с привязкой [style.height.px]
:
<div ... [style.height.px]="notificationBarHeight">
</div>
См. этот стек-блиц для демонстрации.