events - Fire button click in AngularJS -


i want fire button's click event when pressing enter inside input , find quite difficult angularjs.

my view (simplified, updated):

<!doctype html> <html lang="en" ng:app="test">     <head>         <meta charset="utf-8" />         <title>test</title>         <link rel="stylesheet" href="css/app.css" />     </head>     <body ng-controller="testcontroller">         <button ng-click="onbutton1click()" class="btn1">click me</button>         <button ng-click="onbutton2click()" class="btn2">don't click me</button>         <script src="lib/jquery/jquery.js"></script>         <script src="lib/angular/angular.js"></script>         <script src="js/testcontroller.js"></script>     </body> </html> 

my controller view:

'use strict';  angular.module('test', []) .controller('testcontroller', ['$scope',     function($scope) {          $scope.onbutton1click = function() {             alert("hello");         }          $scope.onbutton2click = function() {             $('.btn2').click();         } }]) 

i simplified code this. when click on btn2 error

$apply in progress

no, can't call $scope.onbutton1click() directly, must simulate btn1 click.

this took me while figure out (lots of fiddles).

<form id="nowsorting" ng-submit="getdata(sc_user)">now sorting soundcloud likes of <input type="text" ng-model="sc_user"><input type="submit" value="sort"></form>

make form , use ng-submit fire event (likely function).

then create 2 inputs (one "text" , other "submit").

then pushing enter should fire ng-submit event/function.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -