Implementing automatic scrolling to the bottom while using ng-repeat in Ionic

I've been dealing with a frustrating issue while working on my mobile chat app using Ionic, Angular, and Firebase. The message exchange functionality is fine, but I can't seem to get the auto-scroll feature to work when new messages are received. I've tried using $ionicScrollDelegate, scroll-glue Directive, jQuery functions, and more, but nothing seems to solve the problem.

This is the chat page

<div ng-controller="ChatController as chatCtrl" id="chats_page" class="upage-content vertical-col left hidden has-subheader">
                        <div class="bar bar-subheader subheader-chat">
                          <h2 class="title">{{chatCtrl.status}}</h2>
                        </div>
                <div class="" data-uib="layout/row" data-ver="0"  id="chatBox">


                            <ion-content id="autoscroll" class="widget uib_w_92 d-margins topbar" data-uib="ionic/list" data-ver="0" delegate-handle="mainScroll">
                                <ion-list scroll-glue>
                                <ion-item ng-repeat="msg in chatCtrl.messages" class="item widget uib_w_93 chat-cliente item-text-wrap" data-uib="ionic/list_item" data-ver="0" ng-class="chatCtrl.getRole(msg.role)">{{msg.text}}<a class="chat-time">{{msg.time}}</a>
                                </ion-item>
                            </ion-list>
                            </ion-content>


                </div>

                <div class="bar bar-footer footer-chat" >
                    <i class="placeholder-icon "></i>
                    <textarea type="text" name="msg" placeholder="Type your message..." class="chat-text" ng-disabled="chatCtrl.msgText()" ng-model="myMsg" ></textarea>
                    <button class="button ion-paper-airplane btn-chat-send" ng-click="chatCtrl.sendMsg(myMsg)" ng-disabled="chatCtrl.msgText()" id='btn_send_chat'></button>
                </div>

            </div>

Here's part of the ChatController code snippet:

angular.module('myApp')
.controller("ChatController", ['User','FireBaseApp','$firebase','$ionicLoading','$timeout','$ionicPlatform','$location','$ionicHistory','$timeout','$ionicPopup','$ionicScrollDelegate','$scope',function(User, FireBaseApp ,$firebase, $ionicLoading,$timeout,$ionicPlatform,$location,$ionicHistory,$timeout,$ionicPopup,$ionicScrollDelegate,$scope){

    var self = this;

    ... relevant code here ...

     self.sendMsg = function(msg){
          $scope.myMsg = null;

          $ionicScrollDelegate.scrollBottom();
}

Answer №2

It took me a year, but I finally discovered the solution: dividing my app into angular templates made scrollglue work perfectly.

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

In what way can data be retrieved from within a useEffect block externally?

Essentially, I'm facing an issue with retrieving data from the DateView component in my ChooseCalendar component. The code that retrieves this data is located within a useEffect block due to passing a dateType variable as part of a useState to the com ...

Exploring the way Google indexes Angular-based websites with HTML5 URLs

Currently working on a web application that has the following URL structure: / serves as the landing page without Angular /choose utilizes Angular for search functionality /fund/<code> also Angular based, provides spec ...

Why isn't hot reloading working in ReactJS with Webpack Dev Server even after setting "inline:true"?

What could be the reason for Hot Module Replacement not functioning on webpack dev server? The contents of my package.json file are as follows: { "name": "routing-react", "version": "1.0.0", "description": "Just a little ReactJS Training Ground", ...

The three.js JSON model is rendering larger than expected on the screen

I'm currently working with three.js and I've successfully loaded a JSON file from clara.io into THREE.js. However, the 3D model is too large for my screen. Is there a way to reduce its size when loading it onto the screen? <!DOCTYPE html> ...

Is the script failing to retrieve the innerHTML content?

Here is a snippet of HTML code: <div id="team_players"> <h3>Players</h3> <button class="bold-btn" onclick="teamAct('player_list');">Refresh List ↻</button> <table> <thead> <tr> ...

Tips for troubleshooting syntax errors in JavaScript

Are there any online tools similar to jsfiddle where I can input my JavaScript code and receive feedback on syntax errors, misplaced commas, or semicolons? Here is the example code I am looking to validate: $("#customer").autocomplete({ ...

ReactJS with Flux: Duplicate actions received when switching routes within components

Working on my small React app using React, Router, and Flux has been quite a journey. I've set up 2 routes like this: <Route path="/" exact component={Board} /> <Route path="/table" component={Table} /> Within the Board component, ther ...

Checking for different elements between two arrays in AngularJS can be achieved by iterating through

I am working with two arrays: $scope.blinkingBoxes=[1,3,2] In addition, I have another array named $scope.clickedBoxes where I push several values. Currently, I use the following code to determine if the arrays are identical: if(angular.equals($scope.bli ...

Utilize formData to upload an image to a database with ajax

I'm struggling with the process of uploading an image from an HTML form. The goal is for the form to send the image name along with other data to a PHP page. Instead of using the serialized function, I opted for formData as it has the capability to h ...

Newbie seeking help with Angular Services

I'm struggling to avoid duplicating code by using a service. How can I refactor this into a service and then utilize it in the component? Any assistance would be greatly appreciated. function navigateToLink(myRecords) { this.targetLink = this.data.l ...

Challenges with directing angular directives

Setting up my first angular project and struggling with routing. Initially see the template set by preferencesDirective on page load, works well. Clicking "Change Template" button doesn't switch to another template. Even though debugger shows 404 er ...

Regular expressions can be used to extract all attributes from a webpage that begin with a specified value

I have a simple question - how can I retrieve the values of all attributes that start with http://example.com/api/v3?? For instance, if a webpage includes: <iframe src="http://example.com/api/v3?download=example%2Forg"> <meta twitter="http://exam ...

What steps can I take to create an element that changes upon hovering over it?

I am attempting to implement a mechanism similar to this: https://i.sstatic.net/wZctM.png Here is my current approach: $(document).ready(function(){ $('a').bind('mouseenter', function() { var self = $(this); this.iid ...

Steps for duplicating a div element based on a selected option:

When a user selects a number from a dropdown menu, I want to clone a div that contains personal information based on the chosen number. For example, if they select 8, I want to clone the div 8 times. I tried using a for loop in my JavaScript code to achie ...

Trouble with displaying class object array in Angular 5 using ngFor loop

I am attempting to loop through an array of class objects to populate a dropdown menu in Angular 5. However, the dropdown menu is not showing any options and there are no errors appearing in the browser console. The object array is created based on this m ...

Do you typically define a static variable within a function using `this.temp`?

I am looking to implement a static variable within a function that meets the following criteria: It maintains its value across multiple calls to the function It is only accessible within the scope of that function Below is a basic example of how I am mee ...

Is it possible for Excel to automatically populate specific fields with data obtained from a website using variables?

Currently, our ecommerce platform does not generate invoices. Instead, I manually transfer about 8 data points from the platform to an excel template for creating invoices. This process involves copy-pasting the required information before printing it out. ...

What is the best way to activate the default action/event of an HTML link (anchor element)?

Is there a way to programmatically trigger the default action of an HTML link using JavaScript or jQuery? Essentially simulating a user click on the link. Simply using .click() does not seem to do the trick. $('#alink').click(); // nothing happ ...

I'm currently attempting to set up the React JS package, but unfortunately encountering some errors in the process

I'm having trouble installing react as I keep receiving errors. My system has npm version 8.12.1 installed. I attempted to downgrade react, but that didn't resolve the issue. I tried the following steps: Update npm using: npm install npm -g Dow ...

Error: JSON-JQUERY cannot retrieve the length of a null property

A problem has arisen with its function and is displaying in the console: Uncaught TypeError: Cannot read property 'length' of null. I am unable to understand why this is happening. function shownameplaylist(){ $.getJSON( "js/json/nameplaylist.js ...