Last active
November 15, 2016 12:56
-
-
Save psycalc/0958003fc6818f9ad846ff954dd44f71 to your computer and use it in GitHub Desktop.
Angular Enter Key processing one button
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form ng-submit="myFunct(nick,value)"> //If one button it can process Enter shotcut key | |
<input id="nickinput" type="text" name="name" ng-model="nick" autofocus> | |
<input id="chatinput" type="text" name="name" ng-model="value"> | |
<button ng-click="myFunc(nick,value)">Send</button> | |
</form> | |
//Controller | |
.controller('BodyController', function BodyController($scope, MyData) { | |
$scope.MyData = MyData; | |
$scope.myFunc = function(nick, s) { | |
if(nick && s) { | |
// console.log(s); | |
MyData.send(nick + ": " + s); | |
document.getElementById("nickinput").value = ""; | |
document.getElementById("chatinput").value = ""; | |
nick = undefined; | |
s = undefined; | |
} else { | |
if(!s) document.getElementById("chatinput").style.outline = "thick solid red"; | |
if(!nick) document.getElementById("nickinput").style.outline = "thick solid red"; | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment