0

How can i set true or false when my certain data is selected in angularjs?

example i have data

$scope.obj = {
   'id': 1,
   'id': 2,
   'id': 3
}

<div ng-repeat="myData in ctrl.obj">
   <input type="text" class="form-control" placeholder="Notes" ng-model="ctrl.myData ">
</div>

i want some help when i input data and that is equal to id = 1 it will set my value that is ID 1 else it will set empty, but when i go back to my last selected input box it will still display the value of my input box that is previously inputted. thanks to assist on my logic error :)

Jydon Mah
  • 383
  • 1
  • 9
  • 29

1 Answers1

2

Check the below code which may help you:

var abcAPP = angular.module("abcApp",[]);
abcAPP.controller("abcCtrl",function($scope){
 $scope.obj = [{ 'id': 1}, {'id': 2}, {'id': 3 }]
    $scope.myData = ["1","2","3"];
});
<!DOCTYPE html>
<html ng-app="abcApp">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<body>
<div ng-controller="abcCtrl">
 
<pre ng-bind="myData|json"></pre>
<div ng-repeat="myData1 in obj">
   <input id="{{$index}}" type="text" class="form-control" placeholder="Notes" ng-model="myData[$index]">
</div>
</div>

</body>
</html>
Chiru Adi
  • 647
  • 4
  • 21