如果本文对您有帮助,希望点个赞,建立下友谊关系。

angularJS的ng-keyup

直接上代码我没写指令直接这么用的:

html:

<div class="box_ft_cont">
        <div class="chat_text">
               <textarea id="serializeInfo" data-ng-trim="false" ng-model="chat.sendContent" ng-keyup="sendChats($event)" ui-jq="slimScroll" ui-options="{height:'100%', size:'8px', width:'100%'}" type="text" class="chat-cont"></textarea>
         </div>
         <p class="chat-btn">
                 <span>按enter键发送</span>
                  <button type="submit" ng-click="sendChat()" class="btn btn-primary"><i class="fa fa-paper-plane"></i></button>
         </p>
 </div>

js部分:

  //发送消息
  $scope.sendChat = function () {
      var message = {};
      message.fromUserName = "";
      message.toUserName = $scope.chat.currUserId;
      message.content = $scope.chat.sendContent;
      message.msgType = 0;
      message.sendTime = $filter('date')(new Date(), "yyyy-MM-dd hh:mm:ss");

      myWebsocket.sendMessage(message);
      $scope.chat.sendContent = null;
  }
  $scope.sendChats = function (event) {
      if (event.keyCode == 13) {
          $scope.sendChat();
          return false;
      }
  }

 

posted @ 2017-12-15 16:37  一只喵喵  阅读(213)  评论(0编辑  收藏  举报