变量到 ngmodel 的动态变化不起作用
dynamic change of variable to ngmodel is not working
我正在尝试动态更改日期并让日期反映在视图中,但它没有得到 reflected.When 日期像这样硬编码在一个数组中,它正在视图中反映出来。
我的 date : Array<String> = ['2020-02-25'];
反映在 view.But 中,我的日期在 post 订阅后发生了变化 reflected.Here 是它的代码。
ngOnInit() {
this.sendPostRequest();
}
sendPostRequest() {
var options = { headers: new HttpHeaders({ 'Content-Type': 'text/plain' }) };
this.http.post("http://localhost/android/Api.php?apicall=getattendance", this.postData,options)
.subscribe(data => {
let key, count = 0;
for(key in data) {
this.date.push(data[count]['date']);
count++;
}
对此的观点是
<ion-calendar [(ngModel)]="date"
(change)="onChange($event)"
[options]="options"
type="string"
format="YYYY-MM-DD"
readonly="true"
>
</ion-calendar>
ng-model 接受从指定日期开始的更改 coded.But this.date
没有得到反映。
<div *ngFor="let item of date">
<p>{{ item}}</p>
</div>
也只输出硬编码为 2020-02-05 的日期
ngModel 几乎没有限制。由于你有 (change)
功能,你可以将更改后的值分配给 this.date
onChange(event){
this.date = event.target.value
}
我正在尝试动态更改日期并让日期反映在视图中,但它没有得到 reflected.When 日期像这样硬编码在一个数组中,它正在视图中反映出来。
我的 date : Array<String> = ['2020-02-25'];
反映在 view.But 中,我的日期在 post 订阅后发生了变化 reflected.Here 是它的代码。
ngOnInit() {
this.sendPostRequest();
}
sendPostRequest() {
var options = { headers: new HttpHeaders({ 'Content-Type': 'text/plain' }) };
this.http.post("http://localhost/android/Api.php?apicall=getattendance", this.postData,options)
.subscribe(data => {
let key, count = 0;
for(key in data) {
this.date.push(data[count]['date']);
count++;
}
对此的观点是
<ion-calendar [(ngModel)]="date"
(change)="onChange($event)"
[options]="options"
type="string"
format="YYYY-MM-DD"
readonly="true"
>
</ion-calendar>
ng-model 接受从指定日期开始的更改 coded.But this.date
没有得到反映。
<div *ngFor="let item of date">
<p>{{ item}}</p>
</div>
也只输出硬编码为 2020-02-05 的日期
ngModel 几乎没有限制。由于你有 (change)
功能,你可以将更改后的值分配给 this.date
onChange(event){
this.date = event.target.value
}