How to conditionally hide/show <li> elements in an <ul> list

460 views
Skip to first unread message

Chris Velevitch

unread,
Jan 26, 2016, 9:09:59 AM1/26/16
to AngularJS
In an angular2 app, I want to conditionally hide/show list elements in a unordered list. I'm trying to work out how to create a complex *ngIf= expression with a combination of data from the current list item and an injected value, but I need to listen for changes in the injected value. Below is my current attempt.

import {Component, Input, Output, EventEmitter} from 'angular2/core';
import {SL} from './sl';
import {SLListItem} from "./sl_list_item";
import {SLStatus} from "./sl_status";

@Component({
selector: 'sl-list',
properties: ['sls'],
template: `
<ul>
<li *ngFor="var sl of sls" *ngIf="slStatus.showOrder && sl.quantity > 0 || !slStatus.showOrder">
<sl-list-item [sl]="sl" (change)="itemChanged($event)"></sl-list-item>
</li>
</ul>
`,
providers: [SLStatus],
directives: [SLListItem]
})
export class SLList
{
@Input() sls: SL[];
@Output() onChanged = new EventEmitter<SL>();
sl: SL;
slStatus: SLStatus;

constructor(private _slStatus: SLStatus)
{
this.slStatus = _slStatus;
}

itemChanged(event:SL):void
{
console.log('SLList.itemChanged:',this, event);
this.onChanged.emit(event);
}
}
 

Günter Zöchbauer

unread,
Jan 30, 2016, 8:49:29 AM1/30/16
to AngularJS
Reply all
Reply to author
Forward
0 new messages