Show or hide a pregnancy option, whenever the user selects in the register that is female

5

How do I display or hide an option on a patient record page to tell whether the patient is pregnant or not. The option would only appear if the user checked the Female option.

The image below shows a preview of the registration page. The part marked in red is the part that I want to appear only when sex is female.

    
asked by anonymous 30.09.2015 / 20:40

2 answers

7

Use ng-if or ng-show to control the content display.

ng-if creates and destroys objects in the DOM. ng-show only controls the visibility of the object while preserving it.

The following example:

function SampleController($scope) {
  $scope.sexo = 'M';
}
<html ng-app>
  <head>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script></head><body><divng-controller="SampleController">

      Sexo:
      <select name="sexoSelect" ng-model="sexo">
        <option value="M">Masculino</option>
        <option value="F">Feminino</option>
      </select>

      <div ng-if='sexo == "F"'>
        Gravidez: 
        <select name="gravSelect" ng-model="gravidez">
          <option value="S">Sim</option>
          <option value="N">Não</option>
        </select>
      </div>

    </div>
  </body>
</html>
    
30.09.2015 / 21:19
3

You can use the ng-show or ng-hide <div ng-show="myValue"></div> option.

On the following page you have an example if you need to: AngularJS NgShow

    
30.09.2015 / 20:58