【发布时间】:2018-10-03 04:48:20
【问题描述】:
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>
在控制台中我可以看到数据,但我无法在 Html 页面中获取该数据
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)
在这里,我提到了我的 Html、component.ts 以及我的服务层下拉列表单独不起作用。我不知道该怎么做?
【问题讨论】:
-
您的控制台有错误吗?
-
它会抛出类似 Type Error: connot read property 'choose_payee' undefined 和 Error Context 的错误。但这是另一个输入,除了没有错误。
-
choose_payee您的代码中没有。什么是choose_payee? -
Choose_payee 是另一个输入框
标签: angular angularjs-directive angular2-routing angular2-services angular2-directives