我无法将值从模板传递到组件。 我得到了json响应,我将其显示在视图中。 我想将一个orderId值传递给函数getOrderbyId。 但我得到了不确定的价值......
这是我的.html:
(...)
<ion-item (click)="getOrderById()">
<!-- TODO: OrderbyId not passing id -->
<p primary>Dernière commande :
N°{{response?.last_order_id}}
</p>
<em>Du {{response?.last_order_date}}</em>
<!-- Input to pass orderid for the getOrderById() -->
<input type="text" [(ngModel)]="orderId"/>
</ion-item>
(...)
我的.ts:
import {Page, NavController} from 'ionic-angular';
import {Http} from 'angular2/http';
import {Inject} from 'angular2/core'
import {CustomerService} from './customers.service';
@Page({
templateUrl: 'build/pages/ecommerce/customers/customers.html',
providers: [CustomerService]
})
export class CustomersPage {
response:string;
keyword:string;
results:string [];
allCustomers:boolean = false;
http;
orderId:string;
constructor(public nav: NavController, httpService:Http, private customerService:CustomerService) {
this.customerService = customerService;
this.http = httpService;
this.keyword = '';
}
getCustomerbyEmail() {
this.customerService.getCustomersById(this.keyword)
.subscribe(
response => this.response = response,
error => console.log(error));
}
getOrderById() {
this.customerService.getOrderById(this.orderId)
.subscribe(
response => {
this.response = response;
this.orderId = response.last_order_id;
},
error => console.log(error));
} }
最后服务:
(...)
getOrderById(id) : Observable<any> {
let headers = new Headers();
return this._http.get(this._url+'orders/'+id+this.urlBase, {
headers : headers
}).map(res => res.json().customer);
}
(...)
我不明白为什么我没有从[(ngModel)] =“orderId”获得任何值......
有人有想法吗?
感谢。 阴