简体   繁体   中英

angular2-mdl components applied to Angular 2 Quickstart

I'm trying to use the angular2-mdl component with the Quickstart Angular 2 example ( https://angular.io/guide/quickstart ). I added these dependencies to the default package.json file:

"angular2-mdl": "2.1.0",
"@angular2-mdl-ext/popover": "*",
"@angular2-mdl-ext/select": "0.4.0",

Then I ran "npm install" to download the required modules. I can see the modules just installed in my node_modules dir. Eventually I added:

'angular2-mdl': 'npm:angular2-mdl'

to the default systemjs.config.js file:

map: {
  // our app is within the app folder
  app: 'app', // 'app',
  // angular bundles
  '@angular/core': 'npm:@angular/core/bundles/core.umd.js',
  '@angular/common': 'npm:@angular/common/bundles/common.umd.js',
  '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
  '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
  '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
  '@angular/http': 'npm:@angular/http/bundles/http.umd.js',
  '@angular/router': 'npm:@angular/router/bundles/router.umd.js',
  '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
  // other libraries
  'rxjs': 'npm:rxjs',
  'angular2-in-memory-web-api': 'npm:angular2-in-memory-web-api',
  'angular2-mdl': 'npm:angular2-mdl'
},

and:

'angular2-mdl': { 
    main: 'components/index.js'
  }

to the packages parameter:

packages: {
  app: {
    main: './main.js',
    defaultExtension: 'js'
  },
  rxjs: {
    defaultExtension: 'js'
  },
  'angular2-in-memory-web-api': {
    main: './index.js',
    defaultExtension: 'js'
  },
  'angular2-mdl': { 
    main: 'components/index.js'
  }
}

Then I imported the module in my app.module.ts:

import { MdlModule } from 'angular2-mdl';

and as soon I add the MdlModule to the NgModule imports statement the app stops working:

@NgModule({
   imports: [
     BrowserModule,
     FormsModule,
     MdlModule
   ],
   declarations: [ AppComponent ],
   bootstrap: [ AppComponent ]
 })

The browser console says:

http://localhost:3000/traceur Failed to load resource: the server responded with a status of 404 (Not Found) localhost/:19 Error: (SystemJS) XHR error (404 Not Found) loading http://localhost:3000/traceur (…) (anonymous function) @ localhost/:19

Which is the right way to add angular2-mdl modules to my app?

unfortunately systemjs is not able to read the main entry in the package.json file. There you'll find for angular2-mdl :

"main": "./bundle/angular2-mdl.js"

There is no difference to the modules that you import from @angular. The following should work:

'angular2-mdl': 'npm:angular2-mdl/bundle/angular2-mdl.js'

Remove all other angular2-mdl configuration from your systemjs.config.js file. If it's not working: please post your complete systemjs.config.js file.

For popover and select you need to do the same (there it is "main": "./index.umd.js" so the mapping is 'npm:@angular2-mdl-ext/popover/index.umd.js' )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM