1
I check a parameter with an array that may have values it or not. I have an Ng-Switch does a check on this array. I wish that when it had no value show a Message.
I got to do the ng-switch-when=""
but it didn’t work and I also don’t know if it’s right.
<div ng-repeat="p in ctrl.currentreport.parameters" ng-switch="p.dataType">
<div ng-switch-when="">
Não há dados
</div>
<div ng-switch-when="Integer">
<reportinteger parameter="p"></reportinteger>
</div>
<div ng-switch-when="DateTime">
<reportdate parameter="p"></reportdate>
</div>
<div ng-switch-when="Boolean">
<reportboolean parameter="p"></reportboolean>
</div>
</div>
Good morning, Thavia did not work. The Parameters object will always exist, which may or may not be the data contained in it. And this selection I make by dateType. Would have some other idea?
– Yehudi Mikhael
ng-switch-default works when the value you are checking does not match with any ng-switch-when... How is the p.dataType object?
– Thavia Farias
Inside the "Parameters" I have "dataType": "Integer". but I also have "Parameters":"{}".
– Yehudi Mikhael
I get it, how can it be that you don’t have the datatype for ng-swicth to check, so it won’t even work. You must place your ng-switch inside a <div ng-if=''p.dataType"> <div ng-switch-when="Integer"> <reportinteger Parameter="p"></reportinteger> </div>... </div> and in another div Oce puts the situation counter <div ng-if='! p.dataType"> Something</div>
– Thavia Farias
It didn’t work, the problem is that it’s not entering the <div ng-repeat> which is where I put ng-if. I’ll put the code below
– Yehudi Mikhael
I did a <ng-if="Ctrl.currentreport.Parameters>...</div> test. But when I put <ng-if="Ctrl.currentreport.Parameters.dataType>...</div> it doesn’t run even having dataType inside the Parameters.
– Yehudi Mikhael
Your Ctrl.currentreport.Parameters is an array of objects, so it doesn’t find dataType, so ng-if has to be in the div within ng-repeat. Make a console.log of your object Ctrl.currentreport.Parameters, send it to me q help you in a fiddle.
– Thavia Farias
How would I make this console.log? Do you want to know what is contained in it?
– Yehudi Mikhael
<div ng-repeat="t in Ctrl.currentreport.Parameters">{t}</dv> {"name":"Kminicio","Description":"Km Inicio","dataType":"Integer","defaultValue":null,"value":null,"required":true,"validValues":{}} {"name":"KmFim","description":"Km Fim","dataType":"Integer","defaultValue":null,"value":null,"required":true,"validValues":{}}
{"name":"DataInicio","description":"Data Inicio","dataType":"DateTime","defaultValue":null,"value":null,"required":true,"validValues":{}}
{"name":"Datatermino","Description":"Data Termino","dataType":"Datetime","defaultValue":null,"value":null,"required":true,"validValues":{}}
– Yehudi Mikhael