Reputation: 154
while Am trying to get current element value in angular controller it throwing error as
Cannot read property 'toLowerCase' of undefined
at m.fn.extend.val (jquery.min.js:4:8638)
at h.promise.then.$scope.validatev (product.js:471:43)
var productApp = angular.module('productApp', ['ngRoute','ngProgress']);
Javascript
productApp.controller('AddOrderController',
function($scope,$http) {
$scope.validatev = function (dis,v)
{
console.log(angular.element(dis).val()); //this line throwing error as above mentioned
}
});
HTML
<input type="text" ng-blur="validatev(this,'req:true');" class="form-control"/>
i can't get the value by ng-model / name property as those are dynamic element in my code , so i'm trying to get that element value by this keyword. please help me to get the this value in controller
Upvotes: 0
Views: 197
Reputation: 14440
You can use the $event object :
Javascript
productApp.controller('AddOrderController',
function($scope) {
$scope.validatev = function (event, v) {
console.log(event.currentTarget, v);
}
});
HTML
<input type="text" ng-blur="validatev($event,'req:true');" class="form-control"/>
Upvotes: 0
Reputation: 8121
Why are you not using the ng-model on your input ?
<input type="text" ng-model="modelRef.thingToValidate" ng-blur="validatev(modelRef);" class="form-control"/>
Then In your JS you have a reference to the input value..
$scope.validatev = function (modelRef)
{
console.log(modelRef.thingToValidate);
};
Note I havent tested this but it just demonstrates the ng-model useage..
Example : Angular Form Documentation
Upvotes: 1