javascript - Shift+Enter in Textarea using AngularJS -


this code shows how use directive submit form hitting 'enter' while in textarea. however, able shift+enter , go next line , submit result is. whenever submission made, shows in same line. how submit , show submitted text in next line user intends.

<div ng-app="testapp" ng-controller="mycontroller">   <textarea ng-model="foo" enter-submit="submit()"></textarea><br/>   last submitted text: {{ lastsubmitted }}<br/> </div> 

the angularjs code:

var app = angular.module('testapp', []);  function mycontroller($scope) {    $scope.foo = ""   $scope.lastsubmitted = ""    $scope.submit = function() {     $scope.lastsubmitted = $scope.foo;    } }  app.directive('entersubmit', function () {     return {       restrict: 'a',       link: function (scope, elem, attrs) {          elem.bind('keydown', function(event) {           var code = event.keycode || event.which;            if (code === 13) {             if (!event.shiftkey) {               event.preventdefault();               scope.$apply(attrs.entersubmit);             }           }         });       }     }   }); 

what should do?

it looks need convert \n\r <br/> use ng-bind-html sanitize string.

here code example

you have include angularjs sanitize js file: <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular-sanitize.js"></script>


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -