ngfor

Angular create a recursive loop in template to render comments tree

随声附和 提交于 2019-12-08 03:15:37
问题 Hi I want to render the comments of my applications as comments and its reply's but I dont have idea on how to do it with my data: My data looks like: "comments": [ { "id": "30", "content": "Comment 1", "parent": "0", }, { "id": "31", "content": "Comment 2", "parent": "0", }, { "id": "32", "content": "comment 3", "parent": "0", }, { "id": "33", "content": "sub comment 1-1", "parent": "30", }, { "id": "34", "content": "sub comment 2-1", "parent": "31", }, { "id": "35", "content": "sub sub

Calling a directive after the load of last item in ngFor

允我心安 提交于 2019-12-08 02:54:00
问题 I have a component which contains a table, I call ngFor on a row inside the tBody, the problem is that I need the directive that I apply on the Table to be run after loading the last element of ngFor. Here is my component import {Component} from 'angular2/core'; import {InfScrollTableService} from './inf-scroll-table.service' import {HTTP_PROVIDERS} from 'angular2/http'; import {InfScrollTableDirective} from './inf-scroll-table.directive' @Component({ selector: 'my-app', template: ` <table

Angular 6 Error trying to diff '[object Object]'. Only arrays and iterables are allowed

末鹿安然 提交于 2019-12-08 01:32:23
问题 I think my Problem is that the API delivers an Object instead of an array. So i need to Modify the Object to be an Array ? How could this be done ? Object.assign ? Or Pipe ? Does anyone have a proper example ? I'am still learning Angular this is my second Project so i need some help ;) thy so far ! Here is my code getting data from API ..cant change the API it delivers an Object KnowledgeBaseService import {Injectable, OnInit} from '@angular/core'; import { HttpClient, HttpErrorResponse,

Can ngForIn be used in angular 4?

雨燕双飞 提交于 2019-12-07 00:30:34
问题 I am trying to iterate over the properties of an object using *ngFor but using in . When I try to do this @Controller({ selector: 'sample-controller', template: ` <ul> <li *ngFor="let i in obj"> <b>{{i}}</b>: {{obj[i]}} </li> </ul>` }) class SampleController { obj = {a: 1, b: 2} } I get the error message: Can't bind to 'ngForIn' since it isn't a known property of 'li'. I have included FormsModule and BrowserModule in the imports section of the @NgModule for this component. Is it possible to

Angular *ngFor Array of Objects returning [ERROR: Cannot find a differ supporting object]

南笙酒味 提交于 2019-12-06 15:13:04
I am trying to display in HTML a list of data as follows: Home.ts : this.key = 0 objects = {} // The correct setting was objects = [] thanks! snapshot.forEach(doc => { this.objects[this.key] = { firstname: doc.id, lastname: doc.data().lastname, age: doc.data().age } this.key=this.key+1; } This results in the following when displayed in JSON: console.log(JSON.stringify(this.objects)); // RESULT OF THE CONSOLE: { "0": { "firstname":"james", "lastname":"bond", "age":"87" }, "1": { "firstname":"alex", "lastname":"tali", "age":"59" } } Now when i use: console.log(this.objects[0].firstname); // The

Angular2 access nested JSON

和自甴很熟 提交于 2019-12-06 07:39:06
i´m new to Angular 2 in Typescript.I want to access D and G of my JSON with NgFor. Is there a way to access the elements? [ { "A":"B", "C":{ "D": ["E","F"], "G": ["H"] } } ] I also createt a Plunker: Plunker ngFor can't iterate over an object's keys out of the box. You must handle that yourself. Pipes work well. Example: Updated Plunkr @Pipe({name: 'keys'}) export class KeysPipe implements PipeTransform { transform(value: any, args?: any[]): any[] { let keys = Object.keys(value), data = []; keys.forEach(key => { data.push(value[key]); }); return data; } } 来源: https://stackoverflow.com

Calling a directive after the load of last item in ngFor

戏子无情 提交于 2019-12-06 05:15:25
I have a component which contains a table, I call ngFor on a row inside the tBody, the problem is that I need the directive that I apply on the Table to be run after loading the last element of ngFor. Here is my component import {Component} from 'angular2/core'; import {InfScrollTableService} from './inf-scroll-table.service' import {HTTP_PROVIDERS} from 'angular2/http'; import {InfScrollTableDirective} from './inf-scroll-table.directive' @Component({ selector: 'my-app', template: ` <table class="scrollable" infScrollTable> <thead> <tr> <th class="small-cell">Code</th> <th>Label</th> <th>Area<

Angular 2: *ngFor in *ngFor

ε祈祈猫儿з 提交于 2019-12-06 05:12:12
问题 The following scenario would be pretty easy in javascript but I got some problems getting it worked in Angular. I got an Array like: array a = ( "id" = 0, name = random(), column = 1, 2 or 3, blockrow= 1, 2 or 3) With ngFor I try to create now a grid there all elements out of a get separated in colums and blocks in this column. So my current code (works but nasty). <div *ngFor="let a of a"> <template [ngIf]="a.column=='1'"> <div *ngFor="let b of a"> <template [ngIf]="b.blockrow=='1'"> Block 1

Angular 2 ngFor over even/odd items

为君一笑 提交于 2019-12-05 21:12:38
I have a list with 2 columns, I want the left to show even indices and right to odd. Currently I'm iterating the whole list for every column and filtering with ngIf="odd" or even. Can I make ngFor only do and watch even or odd indices? Would that improve the performance drastically? I don't know how much of a burden is it when half of the DOM elements are ng-if'ed out. The list doesn't change frequently but when it changes it changes completely. You can create a pipe that only returns odd or even items @Pipe({ name: 'evenodd' }) export class EvenOddPipe implements PipeTransform { transform

How to filter items inside “ngFor” loop, based on object property string

回眸只為那壹抹淺笑 提交于 2019-12-05 15:23:54
问题 I need to filter items inside an ngFor loop, by changing the category in a drop-down list. Therefore, when a particular category is selected from the list, it should only list the items containing that same category. HTML Template: <select> <option *ngFor="let model of models">{{model.category}}</option> </select> <ul class="models"> <li *ngFor="let model of models" (click)="gotoDetail(model)"> <img [src]="model.image"/> {{model.name}},{{model.category}} </li> </ul> Items Array: export var