Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to dynamically set width & height in angular 2

I have created global popup components.I want to set width and height anf title dynamically.How do it? modal:

<app-m [(visible)]="show" title="Modal" data-popup="width:300;height:250">
<h1>Sample Title 1</h1>
<button (click)="show= !show" class="btn">Close</button>
</app-m>
like image 833
Apple Orange Avatar asked Jul 20 '18 06:07

Apple Orange


People also ask

How do I set dynamic width?

Answer: Use the JavaScript width() method You can set the width of a <div> box dynamically using the jQuery width() method.

How to dynamically change size of div?

The content height of a div can dynamically set or change using height(), innerHeight(), and outerHeight() methods depending upon the user requirement.

How to make the width and height dynamic in CSS?

Top header with 100% width and 50px height. Left navigation bar with 200px width and dynamic height to fill the screen. A container on the right of the nav bar and under the header with dynamic width and height to fill the screen.


1 Answers

You can do it with decorators. Pass height, width and title model to <app-dialog> like this:

Now in dialog.component.html should be:

<div [@modal] *ngIf="visible" class="dialog" [ngStyle]="{'width': width+'px', 'height': height+'px'}">
    <b>{{title}}</b>
    <ng-content></ng-content>
    <button *ngIf="closable" (click)="close()" aria-label="Close" class="cls">X</button>
</div>
<div *ngIf="visible" class="overlay" (click)="close()"></div>
like image 189
Sanoj_V Avatar answered Oct 04 '22 06:10

Sanoj_V