消防按钮单击AngularJS [英] Fire button click in AngularJS

查看:97
本文介绍了消防按钮单击AngularJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要火按钮的Click事件时pressing一个输入进入里面,我觉得很用AngularJS困难。

I want to fire a button's click event when pressing ENTER inside a input and I find it quite difficult with AngularJS.

我的看法(简体,更新):

<!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>

我对这一观点的控制器:

'use strict';

angular.module('test', [])
.controller('TestController', ['$scope',
    function($scope) {

        $scope.onButton1Click = function() {
            alert("Hello");
        }

        $scope.onButton2Click = function() {
            $('.btn2').click();
        }
}])

我简化了所有的code到这一点。当我点击 BTN2 我得到这个错误

$已经在进行中适用

没有,我不能叫 $ scope.onButton1Click()直接,我必须模拟在 BTN1 点击

No, I can't call $scope.onButton1Click() directly, I must simulate the btn1 click.

推荐答案

这花了我一段时间才能找出(大量小提琴的)。

This took me a while to figure out (lots of fiddles).

&LT;表ID =nowsortingNG提交=的getData(sc_user)&gt;立即排序的SoundCloud喜欢&LT的;输入类型=文本NG模型=sc_user &GT;&LT;输入类型=提交值=排序&GT;&LT; /形式为GT;

请形式和使用NG-提交触发事件(可能是一个功能)。

Make a form and use ng-submit to fire the event (likely a function).

然后,创建两个输入(一个是文,另一个提交)。

Then create two inputs (one is "text" and the other "submit").

然后推进入启动时机的NG-提交事件/功能。

Then pushing enter should fire the ng-submit event/function.

这篇关于消防按钮单击AngularJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆