The challenge of performance in AngularJS Material textareas

When working with a form containing 40-50 textareas, the default option md-no-autogrow can lead to severe performance issues.

The function causing this issue can be found at this link.

Disabling md-no-autogrow means losing the resize functionalities. What alternatives could solve this problem?

Answer №1

Here is a potential solution:

<textarea
    ng-model="$ctrl.model"
    ng-keydown="$ctrl.onKeyDown($event)"
    ng-keyup="$ctrl.onKeyUp($event)"
    md-no-autogrow="true"
  >
onKeyUp(e) {

    if (e.key === 'Enter') {
      return;
    }

    let element = e.target;

    element.style.height = 'auto';
    if (element.scrollHeight > 54) {
      element.style.height = element.scrollHeight + 'px';
    }
}

onKeyDown(e) {
    if (e.key !== 'Enter') {
        return;
    }
    let element = e.target;

    let numberOfLines = element.value.split('\n').length;
    if (numberOfLines >= 2) {
        element.style.height = 'auto';
        element.style.height = (element.scrollHeight + 26) + 'px';
    }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Identifying all Images with JavaScript, Including Asynchronous Ones

Is it possible to use JavaScript to identify all images within a document, even those that are loaded asynchronously (possibly after the DOM is fully loaded)? I am interested in developing a function that can determine if Google Analytics has been loaded ...

What is the best way to switch between components when clicking on them? (The component displayed should update to the most recently clicked one

I am facing a challenge in rendering different components based on the navbar text that is clicked. Each onclick event should trigger the display of a specific component, replacing the current one. I have 5 elements with onclick events and would like to re ...

Sinon causing 'unsafe-eval' error in Chrome extension unit tests

Recently, I've been conducting unit tests on my Chrome extension using Mocha, Chai, and Sinon. However, I encountered an issue when attempting to stub an object from a method: EvalError: Refused to evaluate a string as JavaScript because 'unsafe ...

Combining Angular with Node.js: Uncaught TypeError - error.json() is undefined

I've been diving into a course on integrating node.js with Angular and I'm following the tutorial step by step. However, I encountered an error that has me stuck. Is there anyone who can provide some guidance? The error I'm facing is: Ty ...

Tips for enhancing the user experience with a speed-optimized framework interface

The perception of a web page's loading time by users may not always align with the actual loading time. Here are various scenarios that can affect how users experience page loading: Users waiting for a blank page to load all at once. Some parts of t ...

Activate or deactivate Reactstrap tooltip depending on the button's current state

I've chosen to use Reactstrap (version 6.5.0) for the styling of my ReactJs project. Within my inline form, I have a submit button that remains disabled until the user has input all mandatory details. The goal here is twofold: Show the user a tool ...

Working with JSON data in javascript

While trying to parse JSON data from a server, I came across a strange issue. The data consists of rows of data - essentially a list of lists - and it looks something like this: [[1,2,3],[4,5,6],[7,8,9]] When viewing the JSON data in FF (using Firebug), ...

The performance of CasperJS when used with AngularJS is subpar

If I click on just one button in Casper, everything works perfectly. The code below passes the test. casper.then(function() { this.click('#loginB'); this.fill('#loginEmailField', { 'loginEmail': '<a ...

Having trouble with ion-item click not functioning in Ionic 3?

Working on my Ionic 3 project, I have encountered an issue with the ion-item click listener. The scenario is that I am adding text over a canvas and then attempting to change the style of the text (such as font-family, font-size, bold, and italic). The UI ...

Autocomplete feature enhanced with the ability to validate and clear out

Here's a snippet of my HTML code: <div class="form-group"> <label for="date_chargement" class="col-sm-4 control-label">Minimum loading date:</label> <div class="col-sm-2"> <input type="text" class="form-control te ...

Is using parameterized routes in Node.js a recommended practice or a mistake?

Here is the code snippet I'm working on: router.delete('/delete-:object', function(req, res) { var query; var id = req.body.id; switch (req.params.object) { case 'news' : query = queries['news_del ...

Mobile.changePage does not trigger the pageinit event in jQuery Mobile

I've encountered an issue with handling the on-click event of a button in the following code snippet: $(document).on("click", '.submit_review_button', function(event, ui) { var place = $.data(this, "object"); var ttext = $("#revie ...

What is the best way to link my PHP with MySQL in order to execute an AJAX query?

I am currently working on making this page sortable using a dropdown selection menu. At the moment, there are only two different car makes displayed and they are not sorting properly. My ultimate goal is to enable sorting by make, model, and year, but I ne ...

Numerous Capabilities of Javascript

I have a question about JavaScript and how to implement multiple functions on a webpage. I am new to JavaScript and struggling with getting multiple functions to work successfully. I have searched online but can't find a solution that fits my specific ...

Sending emails with attachments using the power of AngularJS and Java Spring

I have an email sender that works perfectly fine, but it lacks attachment functionality. I attempted the following solution: Here is a simple HTML input: <input type="file" simple-change="uploadFiles($event)"/> This is the JavaScript file picker: ...

Effortlessly transfer data from the URL to your page's content within the Ionic framework with AngularJS

My hybrid mobile application is built using the ionic framework, and I am currently working on a content editing page that requires passing in specific values. To achieve this, I have included parameters in the URL within the routes.js routing file. .stat ...

Sort AngularJS data using multiple select menus

I am trying to create a way to order my data based on multiple select menus. For example: Order : <select ng-model="filterOrder"> <option value="+">- to +</option> <option value="-">+ to -</option> </select> C ...

css: positioning images with overlap in a responsive layout

Two divs have been created with background images, both displaying the same image but in different colors - one grey and the other green. These images are waveforms. Initially, only the grey image (div1) is visible while the green image (div2) remains hid ...

Continuously search for a node and adjust its permissions in a recursive manner

Looking at the tree data structure I have: type DataType = { id: string; access: 'view' | 'none'; isDisabled: boolean; children: DataType[]; }; export const Data: DataType = { id: '1', access: 'view', ...

The struggle of accessing child components using ViewChild in Angular

I am facing an issue with a dialog box that is supposed to display a child component separately. Below is the code for the child component: @Component({ selector: 'userEdit', templateUrl: './edituser.component.html', styleUrls: [ ...