0
私はこのコードを持っている:角度5つのgetクラスのコンテキスト
menu.component.ts私
export class menuComponent {
menu: object;
state: boolean;
constructor() {
this.state = false;
this.menu = [
item: {
action: this.action
}
]
}
action(): void {
this.state = !this.state;
}
}
menu.component.html
<ul *ngFor="let item of menu">
<li>
<a (click)="item.action()"></a>
</li>
</ul>
を内部のクラスの関数と属性を使用する必要がありますアクション楽しい例えば、の状態属性。
まずあなたが**コール**機能に必要: '(クリック)=" item.action () "'。次に、アクションが 'this'にバインドされていることを確認する必要があります:' action:()=> this.action() 'または' action:this.action.bind(this) ' –
[コールバック内の正しい\ 'this \ 'にアクセスするには?](https://stackoverflow.com/questions/20279484/how-to-access-the-correct-this-inside-a-callback ) –
申し訳ありませんが、私はすでにそれを修正 – Carlos