Hello,

i try to create a data filter and i have to say that i am totally new to 
Angular.

So, if a user clicks on a special checkbox the data should be displayed and 
the rest should be blacklisted.
At the moment when a checkbox is checked, the whole list is blacklisted.

At this point, i want to filter the gender. If checkbox 1(-> value = m) is 
checked, each female(-> f) have to be blacklisted.


*home.component.ts*

const HEROES: Hero[] = [
  { id: 11, name: 'Mr. Nice', gender : 'm' },
  { id: 12, name: 'Narco', gender : 'f' },
  { id: 13, name: 'Bombasto', gender : 'm' },
  { id: 14, name: 'Celeritas', gender : 'f' },
  { id: 15, name: 'Magneta', gender : 'm' },
  { id: 16, name: 'RubberMan', gender : 'm' },
  { id: 17, name: 'Dynama', gender : 'f' },
  { id: 18, name: 'Dr IQ', gender : 'm' },
  { id: 19, name: 'Magma', gender : 'm' },
  { id: 20, name: 'Tornado', gender : 'f' }
];


@Pipe({
  name: 'filterPipe'
})
export class FilterPipe implements PipeTransform {

  transform(check: any[], checked: any[]): any {

    return checked
            ? check.filter(gender =>  gender.heroes == checked) 
            : check;
  }

}


*home.component.html*


<div class="row">
<div class="col-xs-12">

<form class="form-inline">
    <div class="form-group">
        *<input type="checkbox" id="checkbox11" [(ngModel)]="checked"  
[ngModelOptions]="{standalone: true}" name="gender" value="m">*
*        <label for="checkbox11">1</label>*
    </div>
    <div class="form-group">
        <input type="checkbox" id="checkbox22" checked="checked">
        <label for="checkbox22">2</label>
    </div>
    <div class="form-group">
        <input type="checkbox" id="checkbox33" checked="checked">
        <label for="checkbox33">3</label>
    </div>
</form>

<h1>{{title}}</h1>
    <h2>My Heroes</h2>
    *<ul class="heroes">*
*      <li *ngFor="let hero of (heroes | filterPipe: checked)"*
*        [class.selected]="hero === selectedHero"*
*        (click)="onSelect(hero)">*
*        {{hero.id}} - {{hero.name}} - {{ hero.gender }}*
*      </li>*
*    </ul>*
    <div *ngIf="selectedHero">
      <h2>{{selectedHero.name}} details!</h2>
      <div><label>id: </label>{{selectedHero.id}}</div>
      <div>
        <label>name: </label>
        <input [(ngModel)]="selectedHero.name" placeholder="name">
      </div>
    </div>

</div>
</div>


Thx for help 
Stefan

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to