我有customer.html:
<app-z-grid title="Tip korisnika" [restPath]="'customertype'" (fillDetailParent)="reinit($event)"></app-z-grid>
<app-z-grid title="Podtip korisnika" [path]='"customerclassification/customerstype.json"' [restPath]="'customerstype'" [isDetail]="'customerstype'" [parentName]="'customertypeCode'" ></app-z-grid>
在我的app-z-grid组件中,我有这个:
pinTab(event: any) {
this.pinned=!this.pinned;
if (this.pinned) {
this.pinnedTabs.push(this.title);
console.log('if stat',this.pinnedTabs);
}
else {
this.pinnedTabs.splice(this.pinnedTabs.indexOf(this.title), 1);
console.log('else state',this.pinnedTabs);
}
在app-z-grid.html我有这样的按钮:
<button (click) ="pinTab(title)" class="btn btn-block-container mousePointer">
<i class="fa fa-thumb-tack" [hidden]="!pinned" style="color:white!important;"></i>
<i class="fa fa-thumb-tack fa-rotate-90" [hidden]="pinned" style="color:white!important;"></i>
</button>
现在,当我点击第一个引脚时,它会将其推入阵列,但是当我点击其他引脚时,它会将其推入其他阵列。有什么建议为什么会发生这种情况?
答案 0 :(得分:1)
组件不共享状态。每个组件(pinnedTabs
)都有自己的状态和支持实例&#34; controller / Class&#34;。如果您想在组件之间共享{{1}}数组,您必须查看角度小组的组件交互手册:https://angular.io/docs/ts/latest/cookbook/component-communication.html