Reputation: 458
Html
<input type="text" class="fulltextbox saving_field" dataid="1" dataname="temperature" dataunit="° F" ng-model="addVt.Temp.value" />
js
var tData = [];
angular.forEach(angSel('.saving_field'), function(v, k){
console.log(v.dataname);
tData.push({id: v.dataid, name: v.dataname, value: v.value, unit: v.dataunit});
});
But I am getting v.dataname
as undefined.
Upvotes: 2
Views: 244
Reputation: 4456
You should be using the following attribute to access it:
v.dataset
Also, the data attributes should have a hyphen in them. Like data-name
and not dataname
.
So HTML would be:
<input type="text" class="fulltextbox saving_field" data-id="1" data-name="temperature" data-unit="° F" ng-model="addVt.Temp.value" />
And in Javascript:
tData.push({id: v.dataset.id, name: v.dataset.name, value: v.value, unit: v.dataset.unit});
See the documentation on how to properly use data attributes.
Upvotes: 2