From b518a4e36079b804cd0ac162e0b0d97c2e78cddd Mon Sep 17 00:00:00 2001 From: Devin Alvaro <devin.alvaro@gmail.com> Date: Wed, 22 Nov 2017 23:33:32 +0700 Subject: [PATCH] Use $scope in ng-controller --- .../src/main/webapp/WEB-INF/chat_driver.jsp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/TugasBesar2_2017/WebApp/src/main/webapp/WEB-INF/chat_driver.jsp b/TugasBesar2_2017/WebApp/src/main/webapp/WEB-INF/chat_driver.jsp index d39b057..f7449b1 100644 --- a/TugasBesar2_2017/WebApp/src/main/webapp/WEB-INF/chat_driver.jsp +++ b/TugasBesar2_2017/WebApp/src/main/webapp/WEB-INF/chat_driver.jsp @@ -34,15 +34,14 @@ <div ng-controller="ChatController as chatController"> <div id="scrollArea"> - <div ng-repeat="chat in chatController.chatList"> + <div ng-repeat="chat in chatList"> <p class="chat-bubble-left" ng-if="chat.from === 'them'">{{chat.text}}</p> <p class="chat-bubble-right" ng-if="chat.from === 'me'">{{chat.text}}</p> </div> - <div scroll-to-bottom=""></div> </div> <div class="chat-box"> - <form class="form-chat-box" ng-submit="chatController.addChat()"> - <input class="text-input" ng-model="chatController.chatText" + <form class="form-chat-box" ng-submit="addChat()"> + <input class="text-input" ng-model="chatText" placeholder="Enter a message"> <input class="send-button" type="submit" value="Kirim"> </form> @@ -68,18 +67,18 @@ </script> <script> angular.module('chatApp', []) - .controller('ChatController', function () { - this.chatList = []; + .controller('ChatController', function ($scope) { + $scope.chatList = []; - this.addChat = function () { - if (this.chatText.length !== 0) { - this.chatList.push({ + $scope.addChat = function () { + if ($scope.chatText.length !== 0) { + $scope.chatList.push({ from: 'me', text: this.chatText }); } - this.chatText = ''; + $scope.chatText = ''; }; }); </script> -- GitLab