而不是單個可變this.selectedMonth
,使用yearData.selectedMonth
每年數據。
updated plunkr
HTML與{{yearData.selected}}
<div class="container">
<div *ngIf="isActive[i1]">
<div class="grey-header">
Selected month:{{yearData.selected}}
</div>
</div>
</div>
JS設置改變
添加selected
關鍵在你OSDATA。
現在每行點擊,設置this.osData[i].selected = month;
this.osData= [{"cardData":[{"view":"Jan","count":1},{"view":"Apr","count":1},{"view":"Jun","count":1}],"selected:": "", "year":2017,"month":"June","family":"AND"},{"cardData":[{"view":"Jan","count":25},{"view":"Oct","count":18},{"view":"Nov","count":14},{"view":"Dec","count":18}],"selected:": "","year":2018,"month":"June","family":"NOU"},{"cardData":[{"view":"Jan","count":21},{"view":"Feb","count":11},{"view":"Mar","count":22},{"view":"Apr","count":18},{"view":"Nov","count":11},{"view":"Dec","count":16}],"selected:": "","year":2019,"month":"June","family":"HNY"},{"cardData":[{"view":"Jan","count":10},{"view":"Jun","count":9},{"view":"Nov","count":5},{"view":"Dec","count":8}],"selected:": "","year":2020,"month":"June","family":"GIN"}]
this.setClickedMonth = function (index, i,month) {
this.selectedMonthIndex = index;
this.osData[i].selected = month;
this.selectedMonth=month;
if (this.isActive[i] === false) {
this.isActive[i] = !this.isActive[i];
this.selectedMonthIndex = '';
} else {
this.isActive[i] = !this.isActive[i];
}
}
}
這個怎麼樣https://plnkr.co/edit/MfXci24ErPxdHEl1Au3e?p=preview –
@yogendarji它的工作的感謝!你。可以請回答我的問題 – forgottofly