javascript - trigger a spacebar click on a textarea programatically -


this textarea

<textarea id="areadata" ng-model="mydata">{{data}}</textarea> 

please how can add spacebar event on textarea click/trigger button

<button type="button" class="btn btn-danger" ng-click="spaceevent">add space bar event</button>  

i trying use not getting right

$timeout(function() {     angular.element('#areadata').triggerhandler('click');   }, 100); 

if understood add space char textarea data when hit button:

app.controller('dummy', function($scope) {   $scope.spaceevent = function () {     $scope.mydata += " ";   }; });  <div ng-app="app" ng-controller="dummy">   <textarea id="areadata" ng-model="mydata"></textarea>   <button type="button" class="btn btn-danger" ng-click="spaceevent()">add space bar event</button> </div> 

jsfiddle

remember need () in ng-click function wrong: ng-click="spaceevent" while right ng-click="spaceevent()"


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -