I´m having some problems while trying to implement ng-keypress in AngularJS. I already looked at another post´s here but still can´t make it work.
Here is my HTML code:
@extends('app')
@section('content')
<div ng-controller="GameController">
<div id="chatZone">
<form action="#" method="get" id="id_form_chat">
<input type="text" id="m" autocomplete="off" ng-model="chatMsg" ng-ng-keypress="keyPressMsg($event)">
</form>
<ul id="messages"><li ng-repeat="m in chatMessages track by $index">@{{m}}</li></ul>
</div>
</div>
@endsection('content')
My Angular code:
(function(){
"use strict";
var module = angular.module('memoryGame', []);
function GameController($scope, $http, $timeout) {
$scope.keyPressMsg = function($event){
console.log("success");
};
}module.controller('GameController', ['$scope', '$http','$timeout', GameController]);
})();
EDIT1: Sorry guys the problem is when i change text in the input box the function in my controller doesn´t trigger itself.. I have edited both angular and html code if u could take a look i would be greatfull
I dont catch anything on console
EDIT2: Solved sorry was misspelling a word..
您可以通过$event.which
获得按下的键代码,因此将$event.keyCode == 13
更改$event.keyCode == 13
$event.which === 13
解决问题
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.