angular - Using ngFor in Array -


i have data showing in console this. want show them in dropdown.

["hello", "hello"] 0:"hello" 1:"hello" length:2 __proto__:array(0) 

this tried:

<select>   <option *ngfor="let x of greeting" [value]="x">{{x}}<option> </select> 

but nothing showing up.

and when use way:

<select>   <option>{{greeting}}<option> </select> 

it shows 1 single item in dropdown hello,hello

update: actual response

{ status: 200, message: "rooms available", available: "yes", remaining_room: 10, price: "[1800,1200]", extra_person_price: "["500","200"]", extra_child_price: "["500","100"]", plan_type: "["ep","pt"]", plan_name: "["summer plan","winter plan"]", } 

response network tab

{status: 200, message: "rooms available", available: "yes", remaining_room: 10,…} available : "yes" extra_child_price : "["500","100"]" extra_person_price : "["500","200"]" message : "rooms available" plan_name : "["summer plan","costume plan"]" plan_type : "["cp","others"]" price : "[1800,1200]" remaining_room : 10 status : 200 

as per our discussion tried iterate wrong variable (which still string), so:

this works: since have mixed data in response, need parse of, in subscribe create object, parse parts need, here's partial data:

getdata() {   this.service.getdata()     .subscribe(data => {       // assign values obj, , parse ones need parse:       this.obj = {"remaining_room":data.remaining_room, "price":json.parse(data.price)}     }) } 

then can refer object in select:

<select>   <option *ngfor="let price of obj?.price">{{price}}</option> </select> 

here's plunker above code.


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -