Component.ts
export class NewExpenseComponent {
users: any[];
toastConfig: ToasterConfig;
constructor(private route: ActivatedRoute,
private router: Router,
private service: ExpensesService,
private http: HttpClient,
private notificationService: NotificationService,
private toasterService: ToasterService
) {
this.service.get_bussiness().subscribe(users => this.users = users,
error => console.log(error));
}
}
Service.ts.
get_bussiness(): Observable<any[]> {
return this.http.get('http://localhost:8000/payment/')
.map(response => response)
.catch(error => Observable.throw(error.statusText));
};
HTML
<div class="form-group">
<label for="inputBusinessType">Business Type</label>
<select #businesstype class="form-control" id="business_type" required [(ngModel)]="model.business_type" name="business_type" #Type="ngModel">
<option disabled>Select</option>
<option (click)="businesstype" *ngFor="let user of users" [value]="user.id">{{user.pay_method}}</option>
</select>
<div *ngIf="Type.errors && (Type.dirty || Type.touched)" class="errors">
<div [hidden]="!Type.errors.required" style="color:red;">
* Please select One
</div>
</div>
</div>
In console im able to see the data but im not able to get that data in Html page
console.log
(3) [{…}, {…}, {…}]
0
:
{id: 1, pay_method: "fuel"}
1
:
{id: 2, pay_method: "card"}
2
:
{id: 3, pay_method: "cash"}
length
:
3
__proto__
:
Array(0)
Here i have mentioned my Html,component.ts and also my service layer dropdown alone not working. i dont know how to do that?
I would to send a comment, but I can't to do that yet. Well, I read your code carefully and don't see obviously errors, expect one.
(click)="businesstype"
What it mean? It's just local template variable which must contains form object. Are you sure that console has no errors? We must to have more info about problem for resolving it.