Scenario
I have scenario where I will parse the document then I will get as a JSON output in key and value format, In key it will contains headings of document and Value will contains corresponding section of the heading. Now I would like to bind the values into ng-model (text boxes in forms), I have 100+ textboxes , I may get different headings from document, if I am getting different headings I like to bind into ng-model with or condition like below code.
Requirement
I like to store all my ng-model names into array for eg:
var array = [$scope.FirstNgModel,$scope.SecondNgModel,$scope.ThirdNgModel,$scope.FourthNgModel,$scope.FifthNgModel]
then I will read the exact matching and I will map.
Current code is below
$.ajax(settings).done(function (response) {
var docparsed = JSON.parse(response);
//angular.forEach($scope.ModelMaping, function (obj) {
angular.forEach(docparsed, function (obj) {
//var ModelVal = obj.value;
//var val = docparsed.find(x => x.key.toLocaleLowerCase() === ModelVal.toLocaleLowerCase())
//obj.key = val.value;
if (obj.key.toLocaleLowerCase() == "first") {
$scope.FirstNgModel = obj.value;
}
if (obj.key.toLocaleLowerCase() == "second") {
$scope.SecondNgModel = obj.value;
}
if (obj.key.toLocaleLowerCase() == "third") {
$scope.ThirdNgModel = obj.value;
}
if (obj.key.toLocaleLowerCase() == "fourth") {
$scope.FourthNgModel = obj.value;
}
if ((obj.key.toLocaleLowerCase() == "fifth") || (obj.key.toLocaleLowerCase() == "sixth")) {
$scope.FifthNgModel = obj.value;
}
});