javascript - AngularJS if statement with ng-repeat -
I have trouble using it as well as a repeat statement.
The data is as follows:
Module: array [1] 0: Object embeds: "iframe width =" 600 "height =" 338 "src = "Https://www.youtube.com/add/UqdDAn4_iY0" frameborder = "0" permissible = "" style = "margin: 0 px auto; Display: Block; "& Gt; & lt; / iframe & gt; Type: "Embed" 1: Object Source: "https://m1.behance.net/rendition/modules/127899607/disp/072cebf2137c78359d66922ef9b96adb.jpg" Type: "Image"
Therefore, if there is an image of the module, then I have to get the image. If there is a type embed in it, then I want to get the iframe. My current view code is:
& lt; Div ng-repeat = "project.modules in project" ng-if = "project.type == 'image'" & gt; & Lt; Img src = "{{project.src}}" class = "IMG-responsive IMG-centric" alt = "{{project.name}}" /> & Lt; / Div & gt;
This works well if I take the NG-if console outputs the following error:
Error: Multiple instructions [ngRepeat, NGIF ] Are asking for transit:
You can use filters instead of using ngIf. Your code will:
& lt; Div ng-repeat = "project.modules | filter: {type: 'image'}" & gt;
And it will work.
The solution you are trying to perform in your code can not be done as ngIf and ngRepeat try to delete and replace both
check this problem
Also check the use of filters
and this question will be useful in using NGRPit with filters
Comments
Post a Comment