Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
14
rated 0 times [  19] [ 5]  / answers: 1 / hits: 43998  / 11 Years ago, thu, september 12, 2013, 12:00:00

I want display a select box if unity_variable equals true or just the unity if not unity_variable equals false



I ve try this :



<div ng-if=question.unity_variable == true>
<select>
<option data-ng-repeat=unit in question.unity>{{unit.value}}</option>
</select>
</div>
<div ng-if=question.unity_variable == false || question.unity_variable == ''>
{{question.unity}}
</div>


And this :



<div ng-show=question.unity_variable == true ng-hide=question.unity_variable ==  false || question.unity_variable == ''>
<select>
<option data-ng-repeat=unit in question.unity>{{unit.value}}</option>
</select>
</div>
<div ng-show=question.unity_variable == false || question.unity_variable == ''>
{{question.unity}}
</div>


so if i didn't put the ng-show that make for each question a select box with unity or display the twice but not respect the condition...
Please help to find my mistake !



enter



EDIT :



My Json look like this for displaying controls to build a form :



{id: 01,
questions: [
{name: confidential data, dbcolumn:confidential data, control: input, default_value: , unity: [{value: mmol/l}, {value: autre}], unity_variable: true, isnull: 0, size:180px, data_type:number, max_length: 3},
{name: confidential data, dbcolumn:confidential data, control: input, default_value: , unity: , isnull: 1, size:180px, data_type:number, max_length: 2},
{name: confidential data, dbcolumn:confidential data,control: select, default_value: [{name:Femme, value: Femme}, {name:Homme, value: Homme}], unity: , isnull: 0, size:196px, data_type:string}
]
}


My html code is :



<table style=display: inline-block; float: left; max-width: 510px;>
<tr data-ng-repeat=question in group.questions>
<td>{{question.name}}</td>
<td>
<div ng-switch on=question.control style=display: inline-block;>
<div ng-switch-when=input>
<input type=text style=width: {{ question.size }}; data-isnull={{question.isnull}} name={{question.dbcolumn}} id={{question.dbcolumn}} placeholder={{question.default_value}} maxlength={{question.max_length}} />
</div>
<div ng-switch-when=textarea>
<textarea style=width: {{ question.size }}; data-isnull={{question.isnull}} name={{question.dbcolumn}} id={{question.dbcolumn}} placeholder={{question.default_value}}></textarea>
</div>
<div ng-switch-when=checkbox>
<input type=checkbox data-isnull={{question.isnull}} name={{question.dbcolumn}} id={{question.dbcolumn}} />{{question.default_value}}
</div>
<div ng-switch-when=select>
<select style=width: {{ question.size }}; data-isnull={{question.isnull}} name={{question.dbcolumn}} id={{question.dbcolumn}}>
<option data-ng-repeat=choice in question.default_value value={{choice.value}}>{{choice.name}}</option>
</select>
</div>
<div ng-switch-when=p>
<p style=width: {{ question.size }}; data-isnull={{question.isnull}} name={{question.dbcolumn}} id={{question.dbcolumn}}><b>{{question.default_value}}</b></p>
</div>
<div ng-switch-default>
<!-- default action -->
</div>
</div>
</td>
<td>
<div ng-if=question.unity_variable == true>
<select>
<option data-ng-repeat=unit in question.unity>{{unit.value}}</option>
</select>
</div>
<div ng-if=question.unity_variable == false || question.unity_variable == ''> {{question.unity}} </div>
</td>
</tr>




if i try just the simply code :



<div ng-if=1 == 1>true</div>
<div ng-if=1 == 2>false</div>


The result show me true and false so i ve a syntaxe error


More From » angularjs

 Answers
25

This works for me:



<div ng-if=question.unity_variable>
<select>
<option data-ng-repeat=unit in question.unity>{{unit.value}}</option>
</select>
</div>
<div ng-if=!question.unity_variable>
{{question.unity}}
</div>

[#75734] Wednesday, September 11, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
lawrencem

Total Points: 153
Total Questions: 102
Total Answers: 98

Location: Mauritania
Member since Sun, Oct 17, 2021
3 Years ago
lawrencem questions
;