2016-10-12 2 views
0

Ich brauche headerExpand Eigentum von app.component zu nennen, aber wenn ich versuche, dies zu machen, zeigen sie mir dies in der Konsole:Ich muss von einer anderen Komponente öffentliche Methode erhalten in Angular 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; 
    } 
} 

Antwort

Verwandte Themen