Example to add angular2 material component

6,008 views
Skip to first unread message

Dmitry Vlasenko

unread,
Mar 19, 2016, 12:09:29 PM3/19/16
to angular-material2
Hello. I need help with this lib. I want to add mdbutton component to my template. How can i do it.
I've installed 
npm install --save @angular2-material/core @angular2-material/checkbox @angular2-material/button
 And then, i added to my component *.ts file.
import {MdButton} from '@angular2-material/button';
But, i have error:
(index):92 Error: Error: XHR error (404 Not Found) loading http://localhost:5555/node_modules/@angular2-material/package.json(…) "Report this error at https://github.com/mgechev/angular2-seed/issues"

What can i do with it? 

Jaakko Jokinen

unread,
Mar 24, 2016, 3:42:26 PM3/24/16
to angular-material2
Your import statement is slightly incorrect. It should be:

import {MdButton} from '@angular2-material/button/button';

The file structure goes as follows node_modules/@angular2-material/button/button.ts.

Juan Carlos Gutiérrez Barquero

unread,
Apr 3, 2016, 4:34:29 PM4/3/16
to angular-material2
I was having a similar problem where I was getting:
angular2-polyfills.js:322 Error: Unable to load script http://localhost:3000/@angular2-material/button/button.js(…)

Clearly the path was missing the node_modules folder. I solved this by adding to System.config:
map: {
 
'@angular2-material': 'node_modules/@angular2-material'
},

Also if you are getting:
system.src.js:2894 Uncaught Error: Module http://localhost:3000/node_modules/@angular2-material/button/button.js interpreted as cjs module format, but called System.register.

You need to change the suggested config from:
'@angular2-material/core': {
 format
: 'cjs',
 defaultExtension
: 'js',
 main
: 'core.js'
},
To:
'@angular2-material/core': {
 format
: 'register',
 defaultExtension
: 'js',
 main
: 'core.js'
},

Best!

RamV

unread,
Apr 13, 2016, 9:22:44 AM4/13/16
to angular-material2
Anyone able to solve this? I am getting the same error. Is there any plnkr or repo with an example?

Todd LaMothe

unread,
Apr 13, 2016, 12:48:05 PM4/13/16
to angular-material2
Juan Carlos's suggestion worked for me - was missing the proper mapping in System.config.

Stéphane Mourgues

unread,
Apr 14, 2016, 8:24:58 AM4/14/16
to angular-material2
Upgrading to 2.0.0-alpha2 solved many issues. If it's not enough I've published this small example which should work out of the box: https://github.com/StephaneMourgues/angular2-openlayers3-material

Anderson Vasconcelos Pires

unread,
Apr 22, 2016, 12:09:55 AM4/22/16
to angular-material2
Hi,

After try a lot of things, I remove the packageConfigPaths in System.config and works for me. I don't know why they add this in angular2-seed repository.


System.config({
"defaultJSExtensions": true,
"packageConfigPaths": [
"/node_modules/*/package.json",
"/node_modules/**/*/package.json"
]

Robert Eastham

unread,
Apr 26, 2016, 7:39:52 AM4/26/16
to angular-material2
Much appreciated Stephane, merci boucoup!

Dennis Smolek

unread,
May 18, 2016, 7:12:35 PM5/18/16
to angular-material2
+1 * 1000

This is what caused the issue for me. I couldnt load all sorts of stuff in the RC and I was freaking out.. Many things in third party Angular2 stuff has had issues with the switches in the RC's so I assumed it was something else and not the seed..

Big thanks..

-D

Sergey Khoroshavtsev

unread,
May 19, 2016, 3:47:55 PM5/19/16
to angular-material2
You need in the file systejs.config.js add mapping:

var map = {
'app': 'app', // 'dist',
'rxjs': 'node_modules/rxjs',
'angular2-in-memory-web-api': 'node_modules/angular2-in-memory-web-api',
'@angular': 'node_modules/@angular',
'@angular2-material': 'node_modules/@angular2-material'
};

var materialPackages=[
'@angular2-material/core',
'@angular2-material/button',
'@angular2-material/card',
'@angular2-material/checkbox',
'@angular2-material/icon',
'@angular2-material/input',
'@angular2-material/list',
'@angular2-material/progress-bar',
'@angular2-material/progress-circle',
'@angular2-material/radio',
'@angular2-material/sidenav',
'@angular2-material/toolbar'
];
materialPackages.forEach(function(pkgName) {
var pkg=pkgName.split('/');
packages[pkgName] = { main: pkg[1]+'.js', defaultExtension: 'js' };
});



суббота, 19 марта 2016 г., 18:09:29 UTC+2 пользователь Dmitry Vlasenko написал:
Message has been deleted

Emi Smith

unread,
May 20, 2016, 12:47:48 AM5/20/16
to angular-material2
For RC.1, use this:

protected SYSTEM_CONFIG_DEV: any = {
defaultJSExtensions: true,
packageConfigPaths: [
`${this.APP_BASE}node_modules/*/package.json`,
`${this.APP_BASE}node_modules/**/package.json`,
`${this.APP_BASE}node_modules/@angular/*/package.json`,
`${this.APP_BASE}node_modules/@angular2-material/*/package.json`
],
paths: {
[this.BOOTSTRAP_MODULE]: `${this.APP_BASE}${this.BOOTSTRAP_MODULE}`,
'rxjs/*': `${this.APP_BASE}rxjs/*`,
'app/*': `/app/*`,
'*': `${this.APP_BASE}node_modules/*`
},
packages: {
rxjs: { defaultExtension: false }
}
};

Hyunwoo Bae

unread,
Jul 19, 2016, 3:07:55 AM7/19/16
to angular-material2
systemjs.config.js

var materialPkgs = [
    'core',
    'button',
    'checkbox',
  ];

function packMaterial(pkgName) {
    packages['@angular2-material/' + pkgName] = { main: pkgName + '.js', defaultExtension: 'js'};
  }

var setMaterialConfig = packMaterial;
  materialPkgs.forEach(setMaterialConfig);


2016년 3월 20일 일요일 오전 1시 9분 29초 UTC+9, Dmitry Vlasenko 님의 말:

Siarhei Hladkou

unread,
Jul 22, 2016, 3:33:56 PM7/22/16
to angular-material2
Thanks, this works with rc4 as well. I spent days looking how to make ng2-m friend with rc4.

Heinz Bigler

unread,
Feb 15, 2017, 4:45:20 PM2/15/17
to angular-material2
In the current angular-seed project add to seed.config.ts

SYSTEM_CONFIG_DEV: any = {
    defaultJSExtensions: true,
    paths: {

...
'@angular/material': 'node_modules/@angular/material/bundles/material.umd.js',
...


or add @angular/material as an additional package to project.config.ts (which seems to be the recommended way)

like:

let additionalPackages: ExtendPackages[] = [{
      name: '@angular/material',
    // Path to the package's bundle
      path: 'node_modules/@angular/material/bundles/material.umd.js'
    }];
    this.addPackagesBundles(additionalPackages);
Reply all
Reply to author
Forward
0 new messages