ngfor

How to iterate through an Object attributes in Angular 2

有些话、适合烂在心里 提交于 2019-12-03 09:43:47
Here's my object (It has n number of dynamic keys. I've only shown two in the example below) let obj = { abc:["some text", "some more text"], xyz:["more text", "what do you think?", "I'm tired now"] } Here's my attempt to loop throw the above and print all the values <div *ngFor='let item of obj ; let i = index;'> <p *ngFor="let value of obj.i">{{value}} </div> But the above doesn't appear to work. What am I doing wrong and what's the correct syntax? You could do something like this: <li *ngFor="let o of obj"> <p *ngFor="let objArrayElement of generateArray(o)"> {{objArrayElement}} </p> </li>

Angular 2+ - check if Pipe returns an empty subset of original list

为君一笑 提交于 2019-12-03 08:56:12
问题 I have a list of strings that I want to iterate through, but I want to be able to filter them using a search term. Like this: <div *ngFor="#item in list | search: searchTerm">{{ item }}</div> My question is: how can I check if the pipe returns an empty subset of the list? In other words if none of the strings matches the search term, I want to display a message saying: "No matches". 回答1: <div *ngIf="(list | search: searchTerm).length === 0"> "No matches" </div> <div *ngFor="#item in list |

Angular 2 performance IE11 *ngFor

混江龙づ霸主 提交于 2019-12-03 06:16:15
I'm trying Angular 2 and I noticed that performance on Internet Explorer 11 is dramatically slow while cycling with *ngFor over 1500 items. It takes about 25sec with IE11 whereas less then 1sec on other browsers. Pausing the debugger I noticed that the code constantly calls isNan function in es6-shim.js. Here the call stack: A working plnkr here: http://plnkr.co/edit/sEujClHmuCbrydIiYQYL?p=preview . The code is very simple: <ul *ngFor="#item of items"> <li>Item: {{item.itemKey}}</li> </ul> //Load items simulating remote load setTimeout(function(){ for (let i = 0; i < 1500; i++) { self.items

Angular2 *ngFor animation of pushed away elements

一笑奈何 提交于 2019-12-03 06:05:42
I've seen many animation tutorials for the entering or leaving elements ("New element" on the image below), but the rest of elements (Element 1 and 2), that are pushed apart usually just teleport to their new location. Is there a way to animate the other elements to move away nicely, like depicted in the attached image? You can use angular2 animation API to achieve it. Plunker Example @Component({ selector: 'my-app', template: ` <div class="container"> <div *ngFor="let item of items; let i = index" class="item" (click)="remove(i)" [@anim]="item.state"> {{ item.name }} </div> </div> <div class=

Angular2 *ngFor in select list, set active based on string from object

牧云@^-^@ 提交于 2019-12-02 23:30:40
I'm trying using the ngFor on my select DropDownList. Have loaded in the options which should be in the dropdown. The code you see here: <div class="column small-12 large-2"> <label class="sbw_light">Title:</label><br /> <select [(ngModel)]="passenger.Title"> <option *ngFor="#title of titleArray" [value]="title.Value">{{title.Text}}</option> </select> </div> Based on this code, it produces a dropdown which look like this image. The problem is that I want to set one of them "Mr or Mrs" as the active one based on the passenger.Title which is a string either "Mr" or "Mrs". Any can help see what I

Angular2 ngFor Iterating over JSON

限于喜欢 提交于 2019-12-02 13:14:37
问题 I´m fairly new to Angular2, and i want to read out a json file. It´s working, that I get the file from a REST-Client, i can save the file in a local variable in a component and furthermore I´m able to read properties of the variable. Now I´m trying to read other properties (Array) with ngFor, but this isn´t working. Here´s the html: //Working <td>{{status.rights}}</td> //Not working <tr *ngFor="let folder of status.recfolders"> <td>{{folder.text}}</td> <td>{{folder.size}}</td> <td>{{folder

how to display json array in angular 2 typescript front end by *ngFor

左心房为你撑大大i 提交于 2019-12-02 09:54:57
Below is angular2 simple front end page:: <table class="table"> <tr> <th>title</th> <th>description</th> </tr> <tr *ngFor="let notes of Note"> <td>{{notes.title}}</td> <td>{{notes.body}}</td> </tr> </table> Below is component code:: in which Note is having export class Note { noteId: number ; title: String ; body: String ; color: String ; isArchive: boolean ; isPinned: boolean ; isTrash: boolean ; } notes:Note[]=[]; ngOnInit() { this.getAllNotes(); } //get all anotes getAllNotes(){ this.noteService.getNotes() .subscribe( // notes => { //tried not working // this.notes = notes; // console.log

call function for every row of *ngFor angular2

巧了我就是萌 提交于 2019-12-02 09:43:59
问题 I have to display a table and call a function for every row of table and the function called once for a row. <tr *ngFor="let item of mf.data" > <td > <button (click)="remove(item)" class="btn btn-danger">x</button> </td> <td>{{item.name}}</td> <td>{{item.email}}</td> <td class="text-right">{{item.age}}</td> <td>{{item.city | uppercase}}</td> </tr> Please suggest how will I implement this functionality?? 回答1: You can add a directive @Directive({ selector: '[invoke]'}) class InvokeDirective {

Angular ViewChildren does not see all children from ngFor immediately

▼魔方 西西 提交于 2019-12-02 05:23:20
问题 I have a strange behaviour of @ViewChildren corresponding to children components generated by ngFor. @ViewChildren query does not see element standing in array for a quite long time. All my code is in the Plunker - see with console opened. This is my main component: @Component({ selector: 'my-app', template: ` <button (click)="addInternalComponent()">Add internal component</button> <app-internal #internals *ngFor="let i of indexes" [index]="i (afterViewInit)="onAfterViewInit()"></app-internal

call function for every row of *ngFor angular2

不想你离开。 提交于 2019-12-02 04:30:53
I have to display a table and call a function for every row of table and the function called once for a row. <tr *ngFor="let item of mf.data" > <td > <button (click)="remove(item)" class="btn btn-danger">x</button> </td> <td>{{item.name}}</td> <td>{{item.email}}</td> <td class="text-right">{{item.age}}</td> <td>{{item.city | uppercase}}</td> </tr> Please suggest how will I implement this functionality?? You can add a directive @Directive({ selector: '[invoke]'}) class InvokeDirective { @Output() invoke:EventEmitter = new EventEmitter(); ngAfterContentInit() { this.invoke.emit(null); } } And