0

I have two $scope values one is array and the other one is json array

$scope.extensions = ["jpg", "xlsx", "pdf", "docx", "mp4"]

$scope.files ={'exten':"jpg","Value":""filepath/data1.jpg"},{'exten':"pdf","Value":""filepath/data2.pdf"},{'exten':"mp4","Value":""filepath/data3.mp4"},{'exten':"jpg","Value":""filepath/data4.jpg"}

enter image description here

if i click on jpg box it should show only data1.jpg and data4.jpg

here is my code for the front end

<div style="padding-left: 100px;margin-top: 50px;">
                <div style="border: 1px solid cornflowerblue; width: 100px; height: 100px;float:left;margin-left: 50px;" ng-repeat="element in extensions">
                    <button ng-click="showFile(element)">{{element}}</button>
                </div>         
            </div>
        <br/>


 <div style="border: 1px solid cornflowerblue; width: 900px; height: 300px;margin-left: 50px;margin-top:100px;" ng-repeat="element in extensions"  ng-show="clickFile==element">
              {{element}}
        </div>
1

2 Answers 2

1

var app = angular.module("testApp", []);
app.controller('testCtrl', function($scope){
  $scope.extensions = ["jpg", "xlsx", "pdf", "docx", "mp4"];

$scope.files =[{'exten':"jpg","Value":"filepath/data1.jpg"},{'exten':"pdf","Value":"filepath/data2.pdf"},{'exten':"mp4","Value":"filepath/data3.mp4"},{'exten':"jpg","Value":"filepath/data4.jpg"}];
  
  
  $scope.showFile = function(element){
    
    $scope.clickFile = element;
    }
})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="testApp" ng-controller="testCtrl">

<div style="padding-left: 100px;margin-top: 50px;">
                <div style="border: 1px solid cornflowerblue; width: 100px; height: 100px;float:left;margin-left: 50px;" ng-repeat="element in extensions">
                    <button ng-click="showFile(element)">{{element}}</button>
                </div>         
            </div>
        <br/>{{clickFile}}
  
  <div style="border: 1px solid cornflowerblue; width: 900px; height: 300px;margin-left: 50px;margin-top:100px;" ng-repeat="file in files | filter:{exten:clickFile}">
              {{file.Value}}
        </div>

</div>

try this

ng-repeat="file in files | filter:{exten:clickFile}"
Sign up to request clarification or add additional context in comments.

Comments

0

You have multiple solutions, like creating your own filter corresponding your case (filter by extension for example)

But concerning your example, you can also set a currentFilterValue, and apply it directly on the ng-repeat.

For example :

showFile = function(element){
  /*...*/
  this.myFilterValue = element;
}


<div style="padding-left: 100px;margin-top: 50px;">
  <div style="border: 1px solid cornflowerblue; width: 100px; height: 100px;float:left;margin-left: 50px;" ng-repeat="element in extensions | filter:myFilterValue">
    <button ng-click="showFile(element)">{{element}}</button>
  </div>
</div>
<br/>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.