我正在使用Angular 2和Angular Material,
我有一个对象,它是一个Object数组,我从我的管道中获取:
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'iterateObject',
pure: false
})
export class IterateObjectPipe implements PipeTransform {
transform(value: any, args: any[] = null): any {
console.log("i am refreshed");
if (!value)
return undefined;
let keys = [];
for (let key in value) {
keys.push({ key: key, value: value[key] });
}
return keys;
}
}
这是我的数组键:
[
{
"key": "RA_Report #",
"value": {
"type": "integer",
"required": true
}
},
{
"key": "RA_CAERS Created Date",
"value": {
"type": "date",
"required": true
}
},
{
"key": "AEC_Event Start Date",
"value": {
"type": "date",
"required": false
}
}
]
我的HTML代码看起来像这样:
<md-form-field class="example-full-width" *ngFor="let item of formData?.properties | iterateObject ">
<input mdInput type="text" placeholder="{{item.key}}" value="{{item.value.type}}" >
</md-form-field>
每次单击输入字段时,输入字段都会刷新,因此我对文本区域的更改将丢失。
也就是说,我点击它的时候,它会刷新,所以我不能在那里做任何解决方案吗?