简体   繁体   English

ionic ng-if不适用于$ index作为模板视图中范围的索引

[英]ionic ng-if Does not work with $index as index of scope in template view

i have an issue with ng-if i have the next code : 我对ng有问题,如果我有下一个代码:

 <ion-slide-box ng-if="sencillo.length && sencillo[$index].custom_sound_path" on-slide-changed="slideHasChanged(sencillo[$index].custom_sound_path)" class="fondo-rojo" show-pager="false" does-continue="true"> <ion-slide on-swipe-right="setR({{sencillo}},$index)" on-swipe-left="setL({{sencillo}},$index)" ng-repeat="senci in sencillo" repeat-done="repeatDone()"> <h1 class="margen-slide slide-estilo">{{senci.title}}</h1> <div style="margin: 0 auto; width:70px" > <a ng-click="play(senci.custom_sound_path)"><img ng-src="img/sonidos/play.png" width="70px" height="70px"></a> <!--<button ng-click="nextSlide()"> >> </button>--> </div> </ion-slide> </ion-slide-box> <ion-slide-box ng-if="sencillo.length && !sencillo[$index].custom_sound_path" on-slide-changed="slideHasChanged('/android_asset/www/raw/'+sencillo[$index].sound_title+'.mp3')" class="fondo-rojo" show-pager="false" does-continue="true"> <ion-slide on-swipe-right="setR({{sencillo}},$index)" on-swipe-left="setL({{sencillo}},$index)" ng-repeat="senci in sencillo" repeat-done="repeatDone()"> <h1 class="margen-slide slide-estilo">{{senci.title}}</h1> <div style="margin: 0 auto; width:70px" > <a ng-click="play('/android_asset/www/raw/'+senci.sound_title+'.mp3')"><img ng-src="img/sonidos/play.png" width="70px" height="70px"></a> <!--<button ng-click="nextSlide()"> >> </button>--> </div> </ion-slide> </ion-slide-box> 

I 'm trying to evaluate if sencillo[$index].custom_sound_path exists , then run the first slidebox else run the second slidebox. 我正在尝试评估sencillo [$ index] .custom_sound_path是否存在,然后运行第一个幻灯片框,否则运行第二个幻灯片框。 The problem is the ng-if always detect sencillo[$index].custom_sound_path as a null value so always the second slidebox is executed, however in another view this works fine, like this: 问题是ng-if如果始终将sencillo [$ index] .custom_sound_path检测为空值,则总是执行第二个幻灯片框,但是在另一个视图中,这样做很好,如下所示:

 <div ng-if="editsimpleRow.custom_sound_path"> <a ng-click="play(editsimpleRow.custom_sound_path)"><img ng-src="img/sonidos/play.png" width="40px" height="40px"></a> <!--<a ng-click="play(editsimple.custom_sound_path)"><img ng-src="img/sonidos/play.png" width="40px" height="40px"></a>--> </div> <div ng-if="!editsimpleRow.custom_sound_path"> <a ng-click="play('/android_asset/www/raw/'+editsimpleRow.sound_title+'.mp3')"><img ng-src="img/sonidos/play.png" width="40px" height="40px"></a> </div> 

i just see the $index value as the only difference, i will appreciate any help!!, thanks, sorry for my english. 我只是将$ index值视为唯一的区别,我将不胜感激!!,谢谢,抱歉我的英语。

I found a solution, i changed my view for : 我找到了解决方案,我改变了以下观点:

 <ion-slide-box ng-if="sencillo.length" on-slide-changed="slideHasChanged('/android_asset/www/raw/'+sencillo[$index].sound_title+'.mp3',sencillo[$index].custom_sound_path)" class="fondo-rojo" show-pager="false" does-continue="true"> <ion-slide on-swipe-right="setR({{sencillo}},$index)" on-swipe-left="setL({{sencillo}},$index)" ng-repeat="senci in sencillo" repeat-done="repeatDone()"> <h1 class="margen-slide slide-estilo">{{senci.title}}</h1> <div style="margin: 0 auto; width:70px" > <a ng-click="slideHasChanged('/android_asset/www/raw/'+sencillo[$index].sound_title+'.mp3',sencillo[$index].custom_sound_path)"><img ng-src="img/sonidos/play.png" width="70px" height="70px"></a> <!--<button ng-click="nextSlide()"> >> </button>--> </div> </ion-slide> </ion-slide-box> 

Then i put the if in my controller, like this: 然后我将if放入控制器中,如下所示:

 $scope.slideHasChanged = function(src,srcdos){ if (srcdos == null){ $scope.play(src); }else { $scope.play(srcdos); } } 

note that the function slideHasChanged now get two parameters instead one. 请注意,函数slideHasChanged现在获得两个参数,而不是一个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM