2017-10-29 185 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); 
}