angularjs - Angular JS with specific select checkboxes -



angularjs - Angular JS with specific select checkboxes -

<body ng-app="workapp"> <div ng-controller="firstclaimcontroller"> <input type="checkbox" ng-click="sbcfunction()"> alternative 1 <input type="checkbox" ng-click="sbcfunction()"> alternative 2 <input type="checkbox" ng-click="sbcfunction()"> alternative 3 <input type="checkbox" ng-click="sbcfunction()"> alternative 4 {{myvalue}} </div> <script type="text/javascript" > var claimcontroller = angular.module('workapp', []); claimcontroller.controller('firstclaimcontroller', function($scope){ // test controller whether works $scope.myvalue = "asdf"; // $scope.sbcfunction = function () { }; }); </script>

the above code , got 4 checkboxes. aim alternative 1 single select , options 2-4 multi-select. if alternative 1 selected, alternative 2-4 should deselected automatically. if alternative 2-4 selected alternative 1 should deselected.

looking improve solution angularjs.

use ng-change.

without functions

this should work in way want to:

<label><input type="checkbox" ng-model="option1" ng-change="multioption1=multioption1&&!option1;multioption2=multioption2&&!option1;multioption3=multioption3&&!option1"> alternative 1</label> <label><input type="checkbox" ng-model="multioption1" value="option2" ng-change="option1=!(multioption1||multioption2||multioption3)"> alternative 2</label> <label><input type="checkbox" ng-model="multioption2" value="option3" ng-change="option1=!(multioption1||multioption2||multioption3)"> alternative 3</label> <label><input type="checkbox" ng-model="multioption3" value="option4" ng-change="option1=!(multioption1||multioption2||multioption3)"> alternative 4</label> example with functions

if prefer utilize functions, can this:

in controller add together this:

$scope.option1=true; $scope.option1changed=function(){ $scope.multioption1=$scope.multioption1&&!$scope.option1; $scope.multioption2=$scope.multioption2&&!$scope.option1; $scope.multioption3=$scope.multioption3&&!$scope.option1; } $scope.multioptionschanged=function(){ $scope.option1=!($scope.multioption1||$scope.multioption2||$scope.multioption3); }

and in view this:

<input type="checkbox" ng-model="option1" ng-change="option1changed()"> alternative 1 <input type="checkbox" ng-model="multioption1" value="option2" ng-change="multioptionschanged()"> alternative 2 <input type="checkbox" ng-model="multioption2" value="option3" ng-change="multioptionschanged()"> alternative 3 <input type="checkbox" ng-model="multioption3" value="option4" ng-change="multioptionschanged()"> alternative 4 example

angularjs checkbox

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -