JSFiddle - React, Tailwind, and code Playground

by Şuayip Ekmekci

HTML

<!-- ex1-3 (ng-click & forEach & push) -->
<body ng-app>
    <div ng-controller="MyCtrl">
		<div ng-click="haveFaseOlanlar()">Have false olanları listele</div>
		<div ng-click="haveTrueOlanlar()">Have true olanları listele</div>
		<div ng-click="ilkListe()">ilk liste</div>
		<br>
		<div ng-repeat="(deneme1,deneme2) in ornekOlsun">
			<span>{{deneme1}} = {{deneme2.text}}</span>
		</div>
	</div>
</body>

JavaScript

function MyCtrl($scope){
    $scope.ornekOlsun = [ // ilk listemiz
        {text:'Lorem', have:true},
        {text:'Lorem-1', have:false},
        {text:'Lorem-2', have:false},
        {text:'Lorem-3', have:true},
        {text:'Lorem-4', have:false},
        {text:'Lorem-5', have:false},
        {text:'Lorem-6', have:true},
        {text:'Lorem-7', have:false},
        {text:'Lorem-8', have:false},
    ];
			
    $scope.ilkListem = $scope.ornekOlsun; // ilk listemizi saklamak için
			
    $scope.haveFaseOlanlar = function() { // ilk liste içerisinde ki have false olanları ayırmak için
        var toplamListe = $scope.ornekOlsun;
        $scope.ornekOlsun = [];
        angular.forEach($scope.ilkListem, function(haveControl) {
            if (!haveControl.have) $scope.ornekOlsun.push(haveControl);
        });
    };
			
    $scope.haveTrueOlanlar = function() { // ilk liste içerisinde ki have true olanları ayırmak için
        var toplamListe = $scope.ornekOlsun;
        $scope.ornekOlsun = [];
        angular.forEach($scope.ilkListem, function(haveControl) {
            if (haveControl.have) $scope.ornekOlsun.push(haveControl);
        });
    };
			
    $scope.ilkListe = function() { // ilk listemizi geri getirmek için
        $scope.ornekOlsun = $scope.ilkListem
    };
}