这就是我的数据在html上的显示方式:
page.html
<ul id="elements">
<li *ngFor="let elem of fetchdata" (click)="log(elem)">
{{elem.title}} {{elem.description}}
</li>
</ul>
page.ts
这里我从localstorage获取数据。
我想要的是 - 当我点击我的文字时,点击的数组对象的title
元素应该更新,
//ARRAY STRUCTURE JUST FOR YOUR NEED
//[{title:"saurabh" , description:"dd" , tagline:"tt", date:"dd"}];
this.fetchdata = JSON.parse(localStorage.getItem('education'));
log(elem,index) {
console.log(elem);
console.log(index);
//WHEN I CLICK, I WANT THE TITLE TO BE UPDATED TO "CLICKED", REST ALL PROPERTIES TO REMAIN SAME
//ARRAY STRUCTURE JUST FOR YOUR NEED
//[{title:"saurabh" , description:"dd" , tagline:"tt", date:"dd"}];
localStorage.setItem("education",JSON.stringify(this.fetchdata));
}
答案 0 :(得分:0)
您想要访问对象elem的标题,只需
log(elem,index) {
console.log(elem.title);
}