ngfor

error display in *ngfor json array object

自闭症网瘾萝莉.ら 提交于 2019-12-01 02:22:42
when fetching json array object from rest api and trying to display in ngfor failed with the reason error EXCEPTION: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays. in [indexes in HomeComponent@5:37] Code import {Component} from 'angular2/core'; import {HomeService} from './home.services'; import {Index} from './index'; @Component({ selector: 'home-app', providers: [HomeService], template: ` <section class="left_side"> <article> <div class="div_home"> <div class="div_homeIndxPartition"> <div class="div

How to create a table rows with an array in angular?

人走茶凉 提交于 2019-12-01 02:10:15
I have an array from 1 until 35: numbersArray = [1,2,3,4,....,35] I want to create a html table like the following: --------------------------- 1 |2 |3 |4 |5 |6 |7 --------------------------- 8 |9 |10 |11 |12 |13 |14 --------------------------- 15 |16 |17 |18 |19 |20 |21 --------------------------- 22 |23 |24 |25 |26 |27 |28 --------------------------- 29 |30 |31 |32 |33 |34 |35 --------------------------- I used the following: <tr *ngFor="let number of numbersArray;"> <td>{{number}}</td> </tr> How can I add </td></tr><tr><td> tags after 6 items in *ngFor ? If it has to be a table and grouped

Angular dynamic table using ngFor

a 夏天 提交于 2019-11-30 18:41:18
问题 I would like to know if it is possible to create a dynamic HTML table from JSON data. The amount of columns and headers should change according to the keys in the JSON. For example this JSON should create this table: { color: "green", code: "#JSH810" } , { color: "red", code: "#HF59LD" } ... And this JSON should create this table: { id: "1", type: "bus", make: "VW", color: "white" } , { id: "2", type: "taxi", make: "BMW", color: "blue" } ... This has to be 100% dynamic though, because I want

Angular 4 *ngFor adding a row div every third column

耗尽温柔 提交于 2019-11-30 15:50:32
问题 I am using Angular 4 with the bulma css framework and I am wondering how I can add a new row (or columns class) every third column. The index variable which prints out 0,1,2 0,1,2 etc. was when I looking at a snippet when using bootstrap. Noticed some comments on maybe I can use the template syntax but didn't get that to work either. <div class="columns"> <div class="column is-one-third" *ngFor="let item of items | async; let index = index"> <app-item-details [item]='item '></app-item-details

Angular2 *ngFor: “Cannot read property '0' of undefined”

筅森魡賤 提交于 2019-11-30 15:45:39
问题 I trying to get data from a JSON file to build a form. Here is a portion of my template: <div class="form-group"> <label for="power">Power</label> <select class="form-control" id="power" required> <option *ngFor="let p of heroes" [value]="p.level">{{p.level}}</option> </select> </div> Here is part of the remote JSON file: { "data": [ { "level": "newbie", "places": [ { "place": "earth", "categories": [ { "category": "human", "values": [ ... It works with no problem and i get newbie and other

Using template driven form with dynamic input list (ngFor)

天大地大妈咪最大 提交于 2019-11-30 15:02:46
I am new to web development and is working on a MEAN stack project using angular2. I am trying to add template-driven form with dynamic list of input using ngFor - however I did observe an abnormal behavior with the way I implement it. I am wondering if I am doing it the right way... Abnormal behavior: If I were to add 2 or more input field and remove the non-last-entries input, the next time i add the new entries, it resets all the entries below the one I just deleted. In addition, somehow the new entries are binding with the entries above? demo of the issue Here is my plunker: http://plnkr

ngFor using ngClass on rows and columns issue

[亡魂溺海] 提交于 2019-11-30 13:47:18
问题 I am using Angular2 and its ngFor. I want to add class to odd and to even rows, so I can separate them visually by color. Here is my code (which does not work really): <div *ngFor="#meeting of meetingList; #index=index; #odd=odd; #even=even;" class="row" [ngClass]="{ odd: odd, even: even } "> <div class="col"></div> <div class="col"></div> </div> Although if I do it like this, code works: <div *ngFor="#meeting of meetingList; #index=index; #odd=odd; #even=even;" class="row" "> <div class="col

Angular io (4) *ngFor first and last

两盒软妹~` 提交于 2019-11-30 06:07:51
I am trying to tell whether an item in an *ngFor is the first or last element to style a container. Is there a way to do something like this? <md-expansion-panel *ngFor="let item of items" *ngClass="{ 'first' : item.isFirst }"> <content></content> </md-expansion-panel> Thanks for any help offered! Inside the ngFor you have access to several variables: index: number: The index of the current item in the iterable. first: boolean: True when the item is the first item in the iterable. last: boolean: True when the item is the last item in the iterable. even: boolean: True when the item has an even