1
votes

I'm using Angular 4 and angular/material. MdToolbar works fine, but when I add MdSidenav to my app template just like the documentation states Node gives me a ReferenceError: navigator is not defined. anyone experience anything similar?

src/app.component.html

<md-sidenav-container>

<layout-header>
    <nav-bar></nav-bar>
    <!-- TODO: Create nav component -->
    <a routerLink="/">Home</a>
    <a routerLink="/about">About</a>
    <a routerLink="/lazy">Lazy</a>
    <a routerLink="/lazy2">Lazy 2</a>
    <a routerLink="/user-profile">User Profile</a>
    <a routerLink="/test-rest">Test Rest</a>
    <a routerLink="/test-route-params">Test Route Params</a>
</layout-header>

<md-sidenav #sidenav class="sidenav">
    <ul>
        <li>Search</li>
        <li>Start a Group</li>
        <li>App Settings</li>
        <li>About</li>
        <li>Help</li>
        <li>Logout</li>
    </ul>
</md-sidenav>

<!--primary router outlet: a dynamic component that the router uses to 
display-->
<router-outlet></router-outlet>

<!-- TODO: Issue with event not emitting via onShown/onHidden -->
<!-- Ref: https://github.com/valor-software/ngx-bootstrap/issues/1886 -->
<app-dialog (dynamicComponent)="onDialogLoad($event)" (onShown)="test()" 
(onHidden)="test2()"></app-dialog>

<!--TODO: example; Delete-->
<button (click)="create()">Create</button>
<simple-notifications [options]="options"></simple-notifications>

<layout-footer></layout-footer>
</md-sidenav-container>

src/app.module.ts

@NgModule({
imports: [
    CommonModule,
    FormsModule,
    ReactiveFormsModule,
    HttpModule,
    TransferHttpModule,
    NgReduxModule,
    MdToolbarModule,
    MdSidenavModule,
    MdIconModule,
    MdCardModule,
    MdInputModule,
    MdButtonModule,
    DialogModule.forRoot([LoginForm]),
    SimpleNotificationsModule.forRoot(), // TODO: remove; testing only
    RouterModule.forRoot(AppRoutes)
],
providers: [ AuthGuard, DialogService ],
declarations: [
    AppComponent,
    HomeView,
    AboutComponent,
    HeaderComponent,
    FooterComponent,
    NavBarComponent,
    LoginForm,
    SideNavComponent
],
exports: [ AppComponent ],
bootstrap : [ AppComponent ]

}) export class AppModule {}

NodeJS error

ERROR { ReferenceError: navigator is not defined at new Platform (/Users/lsorensen/code/OneUnionV1/node_modules/@angular/material/bundles/material.umd.js:3396:36) at ServerAppModuleInjector.get (ng:///ServerAppModule/module.ngfactory.js:177:61) at ServerAppModuleInjector.get (ng:///ServerAppModule/module.ngfactory.js:182:120) at ServerAppModuleInjector.get (ng:///ServerAppModule/module.ngfactory.js:187:108) at ServerAppModuleInjector.getInternal (ng:///ServerAppModule/module.ngfactory.js:477:56) at ServerAppModuleInjector.NgModuleInjector.get (/Users/lsorensen/code/OneUnionV1/node_modules/@angular/core/bundles/core.umd.js:3563:44) at resolveDep (/Users/lsorensen/code/OneUnionV1/node_modules/@angular/core/bundles/core.umd.js:10931:45) at createClass (/Users/lsorensen/code/OneUnionV1/node_modules/@angular/core/bundles/core.umd.js:10795:147) at createDirectiveInstance (/Users/lsorensen/code/OneUnionV1/node_modules/@angular/core/bundles/core.umd.js:10628:37) at createViewNodes (/Users/lsorensen/code/OneUnionV1/node_modules/@angular/core/bundles/core.umd.js:11978:49) at callViewAction (/Users/lsorensen/code/OneUnionV1/node_modules/@angular/core/bundles/core.umd.js:12348:13) at execComponentViewsAction (/Users/lsorensen/code/OneUnionV1/node_modules/@angular/core/bundles/core.umd.js:12287:13) at createViewNodes (/Users/lsorensen/code/OneUnionV1/node_modules/@angular/core/bundles/core.umd.js:12005:5) at createRootView (/Users/lsorensen/code/OneUnionV1/node_modules/@angular/core/bundles/core.umd.js:11883:5) at Object.createProdRootView [as createRootView] (/Users/lsorensen/code/OneUnionV1/node_modules/@angular/core/bundles/core.umd.js:12461:12) at ComponentFactory_.create (/Users/lsorensen/code/OneUnionV1/node_modules/@angular/core/bundles/core.umd.js:9819:46) at ComponentFactoryBoundToModule.create (/Users/lsorensen/code/OneUnionV1/node_modules/@angular/core/bundles/core.umd.js:3434:29) at ApplicationRef_.bootstrap (/Users/lsorensen/code/OneUnionV1/node_modules/@angular/core/bundles/core.umd.js:5016:57) at /Users/lsorensen/code/OneUnionV1/node_modules/@angular/core/bundles/core.umd.js:4803:79 at Array.forEach (native) at PlatformRef_._moduleDoBootstrap (/Users/lsorensen/code/OneUnionV1/node_modules/@angular/core/bundles/core.umd.js:4803:42) at /Users/lsorensen/code/OneUnionV1/node_modules/@angular/core/bundles/core.umd.js:4765:27 at ZoneDelegate.invoke (/Users/lsorensen/code/OneUnionV1/node_modules/zone.js/dist/zone-node.js:365:26) at Object.onInvoke (/Users/lsorensen/code/OneUnionV1/node_modules/@angular/core/bundles/core.umd.js:4132:37) at ZoneDelegate.invoke (/Users/lsorensen/code/OneUnionV1/node_modules/zone.js/dist/zone-node.js:364:32) at Zone.run (/Users/lsorensen/code/OneUnionV1/node_modules/zone.js/dist/zone-node.js:125:43) at /Users/lsorensen/code/OneUnionV1/node_modules/zone.js/dist/zone-node.js:758:57

1
Could you include how you injected mdSideNav and Platform into your controller?Ben Petersen

1 Answers

0
votes

Just exporting MdSidenavModule from NgModule might do the trick in your case.

I had luck breaking out the Material modules(the ones used across multiple components) into their own module, which cleaned up app.module a bit. Then did an import AND export in app.module, something like this:

material.module.ts

import { MdSidenavModule } from '@angular/material';
. 
.
const MATERIAL_MODULES = [
    MdSidenavModule,
    .
    .
];
@NgModule({
    imports: MATERIAL_MODULES,
    exports: MATERIAL_MODULES
})

export class MaterialModule { }

app.module

import { MaterialModule } from '../material.module';
.
.
@NgModule({
    imports: [
        MaterialModule,
        .
        .
    ],
    exports:   [ MaterialModule ],
})