AngularJS - 将 this.value 传递给函数 [英] AngularJS - passing this.value into a function

查看:31
本文介绍了AngularJS - 将 this.value 传递给函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在本机 javascript 中有此代码,它运行正常.它记录文本框的当前值

I have this code in native javascript and it works all right. it logs the textbox's current value

<script>
    var boom = function(val) {
        console.log(val);
    };
</script>

<input type="text" onclick="boom(this.value)"/>

然后我想在不使用模型的情况下在 AngularJS 上做同样的事情.代码如下:

Then I want to do the same on AngularJS without using model. Here is the code:

$scope.boom = function(val) {
    console.log(val);
};

<input type="text" ng-click="boom(this.value)"/>

但它总是记录未定义
为什么?

推荐答案

据我所知,thisng-* 的上下文中是一个 scope.
您可以通过 boom($event.target.value) 访问.

As I know, this in context of ng-* is a scope.
You may access via boom($event.target.value).

这篇关于AngularJS - 将 this.value 传递给函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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