Hey there, I need some assistance. How do I assign the result from a GET method to the $scope.chat variable? Thanks in advance.
app.controller('ChatCtrl', ["$scope","$http", function ($scope,$http) {
$http({
method: 'GET',
url: 'assets/controller/chat/messages.php'
}).then(
function(response1){
$scope.contents=response1.records;
});
$scope.selfIdUser = 50223456;
$scope.otherIdUser = 50223457;
$scope.setOtherId = function (value) {
$scope.otherIdUser = value;
};
var exampleDate = new Date().setTime(new Date().getTime() - 240000 * 60);
**$scope.chat = [{
"user": "bok",
"content": "test1",
"idUser": 1,
"idOther": 2
},{
"user": "bok",
"content": "test2",
"idUser": 1,
"idOther": 2
}];**
$scope.sendMessage = function () {
var newMessage = {
"user": "Peter Clark",
"avatar": "assets/images/avatar-1.jpg",
"date": new Date(),
"content": $scope.chatMessage,
"idUser": $scope.selfIdUser,
"idOther": $scope.otherIdUser
};
$scope.chat.push(newMessage);
console.log(newMessage);
$scope.chatMessage = '';
};
}]);