Navigate down to view the latest md-list-item added to the Angular Material md-list

Struggling to implement a chat feature using Angular and Angular Material. The issue lies in getting the md-list to scroll to the very bottom whenever a new message is added to the messages array. Despite trying various solutions, including using watchCollection, I still haven't been able to achieve the desired scrolling behavior. Perhaps there's something specific to Angular Material that I'm missing.

Here's the HTML snippet:

<md-content flex layout-padding>
        <md-list flex scroll-bottom="vm.messages">
            <md-list-item class="md-3-line" ng-repeat="msg in vm.messages">
                <div class="md-list-item-text" layout="row">
                    <div flex="15"></div>
                    <div flex="70" layout="column">
                        <h3>{{msg.text}}</h3>
                    </div>
                    <div flex></div>
                </div>
            </md-list-item>
        </md-list>
    </md-content>

And here's the Angular Directive code:

angular.module('chat').directive('scrollBottom', function ($timeout) {
    return {
        restrict: 'A',
        scope: {
            scrollBottom: "<"
        },
        link: function (scope, element) {
            scope.$watchCollection('scrollBottom', function (newValue) {
                if (newValue)
                {
                    element.scrollTop =  element.scrollHeight;
                }
            });
        }
    }
})

Answer №1

After commenting on this topic and using the information provided in this Stack Overflow thread, the crucial step is integrating your scrollBottom directive within the md-content element rather than the md-list.

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

Which is better: express.Router() or app.get() for serving routes

I am currently working with Express 4 server for Node.js Express comes with a built-in router, which is utilized as follows: in app.js var router = express.Router(); app.use(router); app.use('/users', usersRoutes); in userRo ...

Exploring AngularJS and the Power of i18next

After researching i18n plugins for Angular, I decided to use the i18next library instead of reinventing the wheel. To implement this, I created a directive named i18n that simply calls the i18n library: define(['app', 'jquery', 'i ...

Node.JS executes Sandbox within a RESTful service environment

Utilizing the Node Restify Module to develop a REST service that accepts POST requests. Inside the service, I am attempting to create a Sandboxed process using the Node Sandbox module in order to execute dynamically inserted JavaScript without impacting th ...

Using React, retrieving the value of a checked radio button from the state

My issue involves a list of radio buttons generated from a map loop containing numbers like 1, 2, and 3. When I select a radio button, it should set a state: <ul className="flex gap-6 justify-center"> {maxPaxArr.map((keypax) => ...

Tips for transferring Json data through Ajax in jquery for an html element?

I am facing an issue while trying to display data from 5 rows of a MySQL database in a table using the success function of a jQuery AJAX call. The data is returned in JSON format. Problem: I am able to retrieve only one row at a time, even though the cons ...

What is the reason for the failure of multiple place markers on a planet object3D?

After spending hours trying to debug a piece of code I wrote 3 years ago using Three.js, I still can't figure out why it's not working anymore. I thought updating all the other code to use ES6 for Three.js would solve the issue, but when I try t ...

Determine in uibmodal /route

Within my code, I have the following: var b = 1 var a = $uibModal.open({ ariaLabelledBy: 'modal-title', ariaDescribedBy: 'modal-body', templateUrl: 'enteModal.html', controller: 'enteCtrl', reso ...

Using ng-if within ng-repeat in an AngularJs table structure

Hey there, I'm currently trying to utilize ng-if within ng-repeat. My condition is if {{dev[2]}} == "". If this condition is met, I want to display <td>Non Valide</td>; otherwise, I simply want to display the data inside 'dev'. I ...

What is the best way to retrieve the ID of a <tr> or <td> element?

When working with JavaScript, I have created a dynamic table where each row is structured as follows: <td id="user[i]['id']">user[i]['name']</td> Within this structure, I am seeking to extract the value user[i]['id&ap ...

Extracting over 100 tweets from the Twitter API with the help of Node.js

I am facing a challenge while trying to fetch over 100 tweets from Twitter in nodejs as I continuously receive an empty array. Here is the approach I have attempted: const MAX_TWEETS = 200; const TWEETS_PER_REQUEST = 100; async function retrieveTweets(T, ...

What is the correct method for storing or uploading an audio file to a designated destination?

Can anyone help me with storing recorded voices in a specific location and uploading the recorded files to that location? Below is a script for uploading an audio file using upload.php: Reference link: //upload link var upload = document.createElement( ...

The concept of asynchronous behavior in ReactJS using the useState hook

I am working on a page to display a list of products. I have included an input file button that allows users to select multiple images. After selecting the images, I use an API to upload them to the server and show the progress visually in the UI with the ...

Getting information about child fields as arguments in the parent using apollo-server

I am currently utilizing apollo-server and am curious if there is a method to obtain information (the fourth argument of a resolver) as it would be received by a specific child field, but within the parent resolver of that child field. My scenario is as f ...

What is causing this console to output twice?

My Objective: I aim to utilize Node.js to launch two child processes sequentially at a specific time, displaying their `stdout` as it streams, occasionally alternating between the two processes. The Desired Output: `Proc 1 log # 1` `Proc 1 log # 2` `Pr ...

Endless loops: How React JS components can render indefinitely

Every time I try to render a screen with the Bar component, it seems to get stuck in an infinite loop without even passing any data. I tested importing react-chartjs-2 and that worked fine, loading just once. However, the other bar chart keeps rendering co ...

What steps can be taken to repair the script?

https://jsfiddle.net/fnethLxm/10/ $(document).ready(function() { parallaxAuto() }); function parallaxAuto() { var viewer = document.querySelector('.viewer.active'), frame_count = 5, offset_value = 500; // init control ...

What is the process for integrating this graph using highcharts?

Check out this link for more information on investment decision-making. There is a visually appealing graph and pie chart featured in the section about Investment Decision-Making in 2016. After noticing that it was created using Highcharts, I wanted to c ...

What is the best way to validate email addresses in Vue.js using watchers?

watch: { email(value) { this.email = value; this.validateEmail(value); }, }, methods() { validateEmail() { // eslint-disable-next-line if (/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<> ...

What is the best way to include a second (concealed) value in a cell using datatables

Query: How can I send specific cell values to a controller using POST method, where one value is visible and the other is hidden? For instance, each cell contains both Time and Date data but only the Time is displayed in the datatable. I need to post both ...

JSP form continues to submit despite JavaScript validation returning false

On my JSP page, I have a form named "deleteCont" and a JavaScript function called "validateDelete". When the user clicks the "Delete contact" button, the "validateDelete" function is triggered successfully, showing an alert message. Unfortunately, even whe ...