Reputation: 185
My JSON array is look like
Array(3)
main2=
[
0:{label: "Name", datatype: "text", lookupname: "null", order: 01"}
1: {label: "DOB", datatype: "date", lookupname: "null", order: "02"}
2: {label: "QRcode", datatype: "qrcode", lookupname: "null", order: "02"}
3: {label: "Image", datatype: "image", lookupname: "null", order: "02"}
]
i tried to generate input form according to datatype.But i can't include button inside the loop,No HTML tags working inside the loop only tags like ion-something working.Like to add button when the data type is barcode or qr code inside the loop
My HTML on ionic
<form>
<ion-item *ngFor="let item of main2">
<ion-label fixed>{{item.label}} : </ion-label>
<ion-input type="text" name="title" *ngIf='item.datatype == "text"'></ion-input>
<ion-input type="text" *ngIf='item.datatype == "radio"'>Checkbox 1</ion-input>
<ion-input type="number" *ngIf='item.datatype == "number"'></ion-input>
<ion-datetime displayFormat="MMMM/DD/YYYY" *ngIf='item.datatype == "date"'></ion-datetime>
<ion-input type="file" name="title" *ngIf='item.datatype == "image"'></ion-input>
<ion-datetime displayFormat="HH:mm" *ngIf='item.datatype == "time"'></ion-datetime>
<ion-input type="number" *ngIf='item.datatype == "number"'></ion-input>
<ion-input type="text" *ngIf='item.datatype == "qrcode"' ></ion-input>
<ion-input type="text" *ngIf='item.datatype == "barcode"'></ion-input>
</form>
Upvotes: 2
Views: 514
Reputation: 1396
Your JSON array is missing a " for order field of:
0:{label: "Name", datatype: "text", lookupname: "null", order: 01"}
Your html is missing the closing tag for <ion-item>
To add buttons:
(Option A) Button in ion-item: you have to use a specific syntax item-left
or item-right
(https://ionicframework.com/docs/2.3.0/api/components/item/Item/)
(Option B) Ion-item as button: you can choose to make the ion-item as a button
HTML
<ion-content>
<form *ngFor="let item of main2">
<ion-item>
<ion-label fixed>{{item.label}} : </ion-label>
...
//Option A
<button ion-button item-right *ngIf='item.datatype == "qrcode"'>Btn</button>
</ion-item>
//Option B
<button ion-item *ngIf='item.datatype == "qrcode"' (click)="test()">{{item.label}} Button</button>
</form>
</ion-content>
Upvotes: 1