我想訪問和更改app.component.ts
變量或訪問方法從其他頁面(otherpage.ts
)或其他組件,如;如何從Ionic中的其他頁面訪問app.component變量和方法?
app.component.ts
@Component({
templateUrl: 'app.html'
})
export class MyApp {
accessedVariable: any;
constructor(){ }
accessedMethod() {
..something
}
}
otherpage.ts
@Component({
selector: 'page-other',
templateUrl: './otherpage.html',
})
export class OtherPage {
constructor() { }
}
是''OtherPage'的MyApp'一個孩子? – bazzells
@ Dr.Geek你能簡單地解釋一下你正在嘗試做什麼,特別是那個accessibleMethod。此外,是app.component和otherpage父母相關或完全分開 – Mehdi
也許這[回答](https://stackoverflow.com/a/44753236/4254681)會有所幫助。如果您只想更改子頁面中的菜單內容,只需使用[service](https://www.tutorialspoint.com/angular2/angular2_services.htm) – Duannx