0

I have two components.

1st components contain a form with textara control, and the 2nd component contains an SVG graph. When user adds more detailed in textarea control and due to that form element get resized, however, I want to detect it to make my SVG graph aligned to that change.

<div id="comp1"> 
<form action="/action_page.php" id="usrform">

<textarea rows="4" cols="50" name="comment" form="usrform">
Enter text here...</textarea>
</form>
<div>

<div id="comp2">
</div>

I want to detect changes whenever comp1 get resized.

1

2 Answers 2

2

Angular provides HostListener Decorator that declares a DOM event to listen for, and provides a handler method to run when that window resize event occurs.

as below

import {HostListener} from '@angular/core';

class AppComponent{
@HostListener('window:resize', ['$event'])
  resize(event) {
    console.log(event);
 }
}

If you want to trigger an resize event on div resize then you can create custom directive as provided by https://www.npmjs.com/package/angular-resize-event package. You can use that package directly or copy the directive source code from here and use it in your project.

Sign up to request clarification or add additional context in comments.

2 Comments

As I understood, window changes only detected when the browser got resized. In my case browser size not get changed, only one <div> is getting resized, which doesn’t fire this event.
Yes @kandarp, but I have added one package details, you can add that package or copy the directive file in you package.
-1

You can do that with the (window:resize) function.

<div id="comp1" (window:resize)="yourFunction($event)">  // <-- add this code fragment
<form action="/action_page.php" id="usrform">

<textarea rows="4" cols="50" name="comment" form="usrform">
Enter text here...</textarea>
</form>
<div>

<div id="comp2">
</div>

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.