AngularJS - 将this.value传递给一个函数 [英] AngularJS - passing this.value into a function
本文介绍了AngularJS - 将this.value传递给一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在原生JavaScript中使用了这段代码,它工作正常。它会记录文本框的当前值
< script>
var boom = function(val){
console.log(val);
};
< / script>
< input type =textonclick =boom(this.value)/>
然后我想在不使用模型的情况下在AngularJS上做同样的事情。这里是代码:
$ $ p $ $ $ $ $ $ $ $ $ $
};
< input type =textng-click =boom(this.value)/>
但它始终记录未定义!
?
解决方案
据我所知,这个
在 ng - *
的背景下是范围
。
您可以通过 boom($ event.target.value)
。
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)"/>
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)"/>
But it always logs undefined!
Why?
解决方案
As I know, this
in context of ng-*
is a scope
.
You may access via boom($event.target.value)
.
这篇关于AngularJS - 将this.value传递给一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文