This is my codepen http://codepen.io/erinbelldeveloper/pen/pyZxZB.
For the appointments page I want to enter a new appointment which works great but
then when I enter a second one there’s a loop showing all the data I only want it to
output the last one.This is what I tried to fix the problem: using the splice method but it
erases the values of the first one so it isn’t accurate. Is there a similar method to print only the last
output without destroying the original data? I also tried ng-show="$last" but it erases
every line for just the last one and I need it to save the first input without modifying
angular.module('App')
.controller('appointmentsController', function($scope, $timeout, $ionicScrollDelegate) {
$scope.hideTime = true;
var alternate,
isIOS = ionic.Platform.isWebView() && ionic.Platform.isIOS();
$scope.sendMessage = function() {
alternate = !alternate;
var d = new Date();
var c=new Date().toJSON().slice(0,10);
d = d.toLocaleTimeString().replace(/:\d+ /, ' ');
$scope.messages.push({
userId: alternate ? '12345' : '54321',
text: $scope.data.message,
time: d,
date: c
});
$scope.messages2.push({
userId: alternate ? '12345' : '54321',
text: $scope.data.message2,
time: d,
date: c
});
if($scope.messages2.length >= 2) {
$scope.messages2.splice(0, 1);
}
$scope.messages3.push({
userId: alternate ? '12345' : '54321',
text: $scope.data.message3,
time: d,
date: c
});
if($scope.messages3.length >= 2) {
$scope.messages3.splice(0, 1);
}
$scope.messages4.push({
userId: alternate ? '12345' : '54321',
text: $scope.data.message4,
time: d,
date: c
});
if($scope.messages4.length >= 2) {
$scope.messages4.splice(0, 1);
}
$scope.messages5.push({
userId: alternate ? '12345' : '54321',
text: $scope.data.message5,
time: d,
date: c
});
if($scope.messages5.length >= 2) {
$scope.messages5.splice(0, 1);
}
delete $scope.data.message;
delete $scope.data.message2;
delete $scope.data.message3;
delete $scope.data.message4;
delete $scope.data.message5;
$ionicScrollDelegate.scrollBottom(true);
};
$scope.inputUp = function() {
if (isIOS) $scope.data.keyboardHeight = 216;
$timeout(function() {
$ionicScrollDelegate.scrollBottom(true);
}, 300);
};
$scope.inputDown = function() {
if (isIOS) $scope.data.keyboardHeight = 0;
$ionicScrollDelegate.resize();
};
$scope.closeKeyboard = function() {
// cordova.plugins.Keyboard.close();
};
$scope.data = {};
$scope.myId = '12345';
$scope.messages = [];
$scope.messages2 = [];
$scope.messages3 = [];
$scope.messages4 = [];
$scope.messages5 = [];
});