I have developed messaging functionality using php as backend and angular 1 on frontend. I am new to angularjs.
My ng-repeat code is
<div ng-repeat="m in messages | orderBy:'+created_at' track by $index">
This prints all my messages in correct order(latest messages first). SQL query returns messages ordered by created_at descending
.
When I send a new message, I am adding that new message to messages
object after inserting it in database. Code is
$scope.messages.push(angular.copy(response.data.data));
This adds new message at the end of the array.
I have also tried unshift
method. It adds new message at the 0th
position.
In both cases, the new message is displayed at the start instead of showing after latest message. Its created_at
value is set as current time stamp.
I want new message to be displayed after latest message.