I am new to angularjs and still learning all the concepts as I go. I am working on a personal project that will use angularjs to get json data and display it to front end HTML page.
Once the page is displayed in HTML there are two columns called rules and servername that has checkbox input field. What I am trying to do is, when the checkbox is clicked, it will create true or false variable based on this attribute check = !check. I would like to access those objects that are created inside ngRepeat scope. I am not sure how I can achieve this with AngularJS. I know I can with JQuery, but I am trying to figure it out with AJS.
Any help getting me to right direction would help a lot. :)
Below is my code and here is my JSFiddle link.
Angular JS code:
angular.module('ucmgmt', [])
.controller('appsCtrl', function ($scope) {
$scope.data = {
"applications": [{
"appname": "maps",
"sitename": "maps.example.com",
"rules": [
"External_Under_Construction",
"Internal_Under_Construction"]
}, {
"appname": "bing",
"sitename": "bing.example.com",
"rules": [
"Bing_Under_Construction"]
}]
};
$scope.process = function ($index) {
console.log("item is checked." + $index);
};
})
HTML Code
<div ng-app="ucmgmt">
<div ng-controller="appsCtrl">
<table class="tg">
<tr>
<th class="tg-031e">Appname</th>
<th class="tg-yw4l">Sitename</th>
<th class="tg-yw4l">Rule</th>
<th class="tg-yw4l">ServerName</th>
<th class="tg-yw4l">Status</th>
</tr>
<tbody ng-repeat="item in data">
<tr ng-repeat="app in item">
<td class="tg-yw4l">{{app.appname}}</td>
<td class="tg-yw4l">{{app.sitename}}</td>
<td class="tg-yw4l">
<ul>
<li ng-repeat="rule in app.rules">
<input ng-click="check = !check" type="checkbox" value="{{rule}}">{{rule}}</li>
</ul>
</td>
<td class="tg-yw4l">
<ul>
<li>
<input ng-click="check = !check; process($index)" type="checkbox" value="SERVER1">SERVER1</li>
<li>
<input ng-click="check = !check" type="checkbox" value="SERVER2">SERVER2</li>
</ul>
</td>
<td class="tg-yw4l">
<ul>
<li>NA</li>
<li>NA</li>
</ul>
</td>
</tr>
</tbody>
</table>
</div>
</div>