Angularjs:如何在没有ng

系统教程 行业动态 更新时间:2024-06-14 17:03:54
Angularjs:如何在没有ng-model的情况下获得输入值(Angularjs: How to get value of input without ng-model)

我需要通过ng-repeat进行一些输入,并且在我的json文件中,我在object中有一个名为name的属性,如下所示:

"url":"find_company", "values":[ { "name":"company name", "type":"input_search" },{ "name":"company_phone", "type":"input_search" } ]

我想在DB中搜索,在搜索中你可以通过任何字段或两个或多个字段找到。 字段称为对象的属性相同。 所以通过ng-keyup我需要发送到我的函数

search(field, value)

两个论点。 我想做这样的事情

<div ng-repeat="value in param.values"> <input ng-if="value.type == 'input_search'" ng-keyup="search(value.name, this.text)" type="text">

如何在不使用ng-model情况下发送此输入的功能文本? this.text是输入值。

I need to make some inputs by ng-repeat, and in my json file I have in object where is a property called name, like this:

"url":"find_company", "values":[ { "name":"company name", "type":"input_search" },{ "name":"company_phone", "type":"input_search" } ]

I want to make search in DB, in search you can find by any field or by two or more field. Field called the same as property of object. So by ng-keyup I need to send to my function

search(field, value)

two arguments. I want to do something like this

<div ng-repeat="value in param.values"> <input ng-if="value.type == 'input_search'" ng-keyup="search(value.name, this.text)" type="text">

How can a send to function text of this input without using ng-model? Where this.text is value of input.

最满意答案

这是你 ngModel做的ngModel :

<div ng-repeat="value in param.values"> <input ng-if="value.type == 'input_search'" ng-model="value.val" ng-keyup="search(value)" type="text">

在你的控制器中:

$scope.search = function( item ) { console.log( item.val ); // Here you have the value using ngModel console.log( item.name ); // Here you have the "name" property of the element inside the loop }

如您所见,您可以使用ngModel并将对象本身传递给该函数,您可以从控制器中的函数访问其属性。

请注意,视图中有this.text - 我不知道它究竟是什么,所以我从示例中删除它以使事情更清楚,但您可以在代码中使用它。

This is how you do it with ngModel:

<div ng-repeat="value in param.values"> <input ng-if="value.type == 'input_search'" ng-model="value.val" ng-keyup="search(value)" type="text">

And in your controller:

$scope.search = function( item ) { console.log( item.val ); // Here you have the value using ngModel console.log( item.name ); // Here you have the "name" property of the element inside the loop }

As you can see, you CAN use ngModel and by passing the object itself to the function you can access its properties from the function in the controller.

Note that there's that this.text in the view - I don't know what it is exactly so I dropped it from the example to make things clearer, but you can use it in your code of course.

更多推荐

value,type,text,ng-repeat,电脑培训,计算机培训,IT培训"/> <meta name="des

本文发布于:2023-04-24 14:16:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/e444829923b8b39b12f7f65fc12a6a40.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何在   Angularjs   ng

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!