0
我需要從app.component調用headerExpand屬性,但是當我試圖讓這一點,讓我這個在控制檯中看到公有方法:我需要從其他成分角2
metadata_resolver.js:559Uncaught Error: Invalid providers for "Page1" - only instances of Provider and Type are allowed, got: [?undefined?]
page1.ts
<pre>
import { Component } from '@angular/core';
import { MyApp } from '../../app/app.component';
@Component({
selector: 'page-page1',
templateUrl: 'page1.html',
})
export class Page1 {
constructor(public miApp: MyApp) {
console.log(miApp.headerExpand);
}
</pre>
app.component.ts
<pre>
@Component({
templateUrl: 'app.html'
})
export class MyApp {
@ViewChild(Nav) nav: Nav;
rootPage: any = Page1;
public headerExpand: boolean;
public pages: Array<{title: string, component: any}>;
constructor(public platform: Platform) {
this.initializeApp();
this.headerExpand = true;
}
initializeApp() {
this.platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
StatusBar.styleDefault();
});
}
openPage(page) {
// Reset the content nav to have just this page
// we wouldn't want the back button to show in this scenario
this.nav.setRoot(page.component);
}
expandHeader(){
this.headerExpand = false;
}
}