HTML code:
1 <!DOCTYPE HTML>2 <HTMLData-ng-app= "APP">3 <Head>4 <Linkrel= "stylesheet"href= "//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">5 <Scripttype= "Text/javascript"src= "Https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js"></Script>6 <Scriptsrc= "Script2.js"></Script>7 </Head>8 9 <BodyData-ng-controller= "Addstylectrl">Ten One A - <Divclass= "Row"> - <Buttonclass= "Col-xs-3"Ng-click= "Closechoosetagsmodal ()">Back</Button> the <Divclass= "Col-xs-6">Choose Tags</Div> - <Buttonclass= "Col-xs-3"Ng-click= "Finishchoosetags ()">Finish</Button> - </Div> - <Div> + <Divclass= "Col-xs-12"> - <Div>You have choosen:</Div> + A <labeldata-ng-repeat= "Selectedtag in Selectedtags"> at ({{Selectedtag}} ) - </label> - </Div> - <Divclass= "Col-xs-12"data-ng-repeat= "category in Tagcategories"> - <Divclass= "Row">{{Category.name}}</Div> - <Divdata-ng-repeat= "tag in Category.tags"> in <Divclass= "Col-xs-4"> - <inputtype= "checkbox"ID={{tag.id}}name= "{{tag.name}}"ng-checked= "isSelected (tag.id)"Ng-click= "Updateselection ($event, tag.id)"> to {{Tag.name}} + </Div> - </Div> the </Div> * <Buttonclass= "Col-xs-12"Ng-click= "Finishchoosetags ()">Finish</Button> $ </Div>Panax Notoginseng - <!--<pre>{{selected|json}}</pre> - the <!--<pre>{{selectedTags|json}}</pre> - + A </Body> the + </HTML>
JS code: (script2.js)
1 /**2 * Created by en on 20/05/15.3 */4 //Code goes here5 6 varIAPP = Angular.module ("App", []);7 8 9 TenIapp.controller (' Addstylectrl ',function($scope) One { A$scope. tagcategories = [ - { -Id:1, theName: ' Color ', - Tags: [ - { -Id:1, +Name: ' Color1 ' - }, + { AId:2, atName: ' Color2 ' - }, - { -Id:3, -Name: ' Color3 ' - }, in { -Id:4, toName: ' Color4 ' + }, - ] the }, * { $Id:2,Panax NotoginsengName: ' Cat ', - tags:[ the { +Id:5, AName: ' CAT1 ' the }, + { -Id:6, $Name: ' Cat2 ' $ }, - ] - }, the { -Id:3,WuyiName: ' Scenario ', the tags:[ - { WuId:7, -Name: ' Home ' About }, $ { -Id:8, -Name: ' Work ' - }, A ] + } the ]; - $$scope. Selected = []; the$scope. Selectedtags = []; the the varupdateselected =function(action,id,name) { the if(Action = = ' Add ' && $scope. Selected.indexof (id) = = 1){ - $scope. Selected.push (ID); in $scope. Selectedtags.push (name); the } the if(Action = = ' Remove ' && $scope. Selected.indexof (ID)!=-1){ About varIDX =$scope. Selected.indexof (ID); the$scope. Selected.splice (idx,1); the$scope. Selectedtags.splice (idx,1); the } + } - the$scope. updateselection =function($event, id) {Bayi varCheckBox =$event. Target; the varAction = (checkbox.checked? ') Add ': ' Remove '); the updateselected (action,id,checkbox.name); - } - the$scope. isSelected =function(ID) { the return$scope. Selected.indexof (ID) >=0; the } the});
Angularjs Determine if the checkbox/check box is selected