2017-10-29 60 views
0

我不能進入到終極版店內財產與角工作。無法訪問終極版店內財產

我在IApp中有兩個屬性,第一個是接口,第二個是數字。

interface AppStoreInterface { 
    layoutInterface: LayoutInterface, 
    numero: number 
} 

我可以毫無問題訪問數,但是當我試圖訪問layoutInterface空話happends。

這是模塊:

export class AppModule { 

    constructor(
    ngRedux: NgRedux<AppStoreInterface>, 
    public devTools: DevToolsExtension 
) { 

    const storeEnhancers = devTools.isEnabled() ? [devTools.enhancer()] : []; 

    ngRedux.configureStore(
     rootReducer, 
     INITIAL_STATE, 
     [], 
     storeEnhancers 
    ); 
    } 
} 

,這是組件:我在做什麼錯

export class MainLayoutComponent implements OnInit { 

    @select(['layoutInterface', 'sidebarStatus']) sidebarStatus$: boolean; 
    @select('numero') test$ :number; 

constructor(
    public translate: TranslateService, 
    public dialog: MdDialog, 
    private ngRedux: NgRedux<AppStoreInterface>, 
    private actions: LayoutActions 
) { 
    const browserLang: string = translate.getBrowserLang(); 
    translate.use(browserLang.match(/en|es/) ? browserLang : 'en'); 

    this.siteStyle = "app"; 
    this.boxed = ""; 
    this.align = "start"; 
    this.currentLang = "en"; 
    this.showSettings = false; 
    this.showLeftButtton = false; 
    this.userLoggedIn = false; 

    //this.store = this.getStoreService(); 
    //this.layoutInterface = this.getLayoutInterface(); 
    } 
} 

回答

0

當您使用@select時,您不會從商店獲得該值,而是獲得該值的Observable。要訪問該值,您需要訂閱Observable

@select(['layoutInterface', 'sidebarStatus']) sidebarStatus$: Observable<boolean>; 
                   ^^^^^^^^^^^^^^^^^^^^ 
@select('numero') test$: Observable<number>; 
         ^^^^^^^^^^^^^^^^^^^ 

您可以直接通過async管訪問它在組件的模板(HTML)。

<span *ngIf="sidebarStatus$ | async">Sidebar</span> 

或者您可以在您的組件的類中明確訂閱它,例如分配值到另一場像sidebarStatus: boolean;

ngOnInit() { 
    this.sidebarStatus$.subscribe(sidebarStatus => this.sidebarStatus); 
}