javascript - How to write directive for to many ng-if condition? -
i have simple form in showing simple text, same text tick , hiding same text based on ng-if conditions. want make directive dont know how. made simple directives 1 seems complicated.
here html
<ul class="list-unstyled carsure-listing-detail"> <li ng-if="!button_clicked && !checkboxmodel.value1"><input type="checkbox" ng-model="checkboxmodel.value1"> right b pillar non-accidented</li> <li ng-if="button_clicked && checkboxmodel.value1"><i class="fa fa-check"></i>right b pillar non-accidented</li> <li ng-if="!button_clicked && checkboxmodel.value1"><input type="checkbox" ng-model="checkboxmodel.value1"> right b pillar non-accidented</li> </ul> here controller
var maincontrollers = angular.module('maincontrollers', []); maincontrollers.controller('startercontroller', ['$scope', '$routeparams', function ($scope, $routeparams) { $scope.checkboxmodel = {}; $scope.button_clicked = false; console.log($scope.button_clicked); $scope.checksubmit = function () { $scope.button_clicked = true; } }]); any suggestions how can achieve same functionality ?
just divide business logic , presentation logic.
in controller:
$scope.firstitemisvisible = !button_clicked && ...(you can put more options here)... && !checkboxmodel.value1; $scope.seconditemisvisible = button_clicked && checkboxmodel.value1 on view:
<li ng-if="firstitemisvisible"> <input type="checkbox" ng-model="checkboxmodel.value1"> right b pillar non-accidented </li> <li ng-if="seconditemisvisible"> <i class="fa fa-check"></i> right b pillar non-accidented </li> the possible case of directive like:
<li put-if1="!button_clicked" put-if2="!checkboxmodel.value1"> ... </li> but redundant , can make skip 1 of equations in cases.
Comments
Post a Comment