Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angularjs: How to get value of input without ng-model

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.

like image 930
kliukovking Avatar asked Nov 30 '25 12:11

kliukovking


1 Answers

since you are using ng-keyup, you can retrieve input value with $event.target.value.


comment: this is fit for normal event like onclick, but not fit for angular.

refer the below example.

angular.module("app", [])
  .controller("myCtrl", function($scope) {
    $scope.showValue = function(val) {
      alert(val);
    }
  });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<div ng-app="app" ng-controller="myCtrl">
  <input type="test" ng-keyup="showValue($event.target.value)">
</div>
like image 156
Pengyy Avatar answered Dec 06 '25 10:12

Pengyy