Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to include angular2-material to angular2 app #872

Closed
micronyks opened this issue Jul 17, 2016 · 4 comments
Closed

How to include angular2-material to angular2 app #872

micronyks opened this issue Jul 17, 2016 · 4 comments

Comments

@micronyks
Copy link

What if I don't use Angular Cli. How can I integrate angular2-material with quick-start app of angular2.

I added @angular2-material/core package. Then I installed other angular2-material components like @angular2-material/button, @angular2-material/card and so on.

systemjs.config.js


/**
 * System configuration for Angular 2 samples
 * Adjust as necessary for your application needs.
 */
(function(global) {
  // map tells the System loader where to look for things
  var map = {
    'app':                        'app', // 'dist',
    '@angular':                   'node_modules/@angular',
    'angular2-in-memory-web-api': 'node_modules/angular2-in-memory-web-api',
    'rxjs':                       'node_modules/rxjs',
    '@angular2-material':         'node_modules/@angular2-material', 
    // <--------------added this above line----------------------
  };
  // packages tells the System loader how to load when no filename and/or no extension
  var packages = {
    'app':                        { main: 'main.js',  defaultExtension: 'js' },
    'rxjs':                       { defaultExtension: 'js' },
    'angular2-in-memory-web-api': { main: 'index.js', defaultExtension: 'js' },
  };
  var ngPackageNames = [
    'common',
    'compiler',
    'core',
    'forms',
    'http',
    'platform-browser',
    'platform-browser-dynamic',
    'router',
    'router-deprecated',
    'upgrade',
  ];

  //<------------------added this below part--------------------------------
var materialPackages=[
    'core',
    //'button',
    //'card',
    'list',
  ];
  materialPackages.forEach(function(pkgName) {
    packages['@angular2-material/'+pkgName] = { format: 'cjs', defaultExtension: 'js'};
  });
 //<----------------------till here---------------------------------


  // Individual files (~300 requests):
  function packIndex(pkgName) {
    packages['@angular/'+pkgName] = { main: 'index.js', defaultExtension: 'js' };
  }
  // Bundled (~40 requests):
  function packUmd(pkgName) {
    packages['@angular/'+pkgName] = { main: '/bundles/' + pkgName + '.umd.js', defaultExtension: 'js' };
  }
  // Most environments should use UMD; some (Karma) need the individual index files
  var setPackageConfig = System.packageWithIndex ? packIndex : packUmd;
  // Add package entries for angular packages
  ngPackageNames.forEach(setPackageConfig);
  var config = {
    map: map,
    packages: packages
  };
  System.config(config);
})(this);

When I run my app I following error,

Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:3000/node_modules/@angular2-material/sidenav/ Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:3000/node_modules/@angular2-material/toolbar/ Failed to load resource: the server responded with a status of 404 (Not Found) localhost/:16 Error: Error: XHR error (404 Not Found) loading http://localhost:3000/node_modules/@angular2-material/button(…)(anonymous function) @ localhost/:16 http://localhost:3000/node_modules/@angular2-material/card/ Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:3000/node_modules/@angular2-material/input/ Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:3000/node_modules/@angular2-material/checkbox/ Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:3000/node_modules/@angular2-material/radio/ Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:3000/node_modules/@angular2-material/icon/ Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:3000/node_modules/@angular2-material/list/ Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:3000/favicon.ico Failed to load resource: the server responded with a status of 404 (Not Found)
angular2 npm angular2-material

@frankcalise
Copy link

In your materialPackages.forEach, for each package did you try calling out the main: with pkgName? See https://github.com/kara/puppy-love/blob/master/src/system-config.ts

@micronyks
Copy link
Author

@frankcalise - I tried this also but also it is not working.

NOTE: I don't use angular cli.

(function(global) {

    // map tells the System loader where to look for things
    var map = {
        'app': 'app', // 'dist',

        '@angular': 'node_modules/@angular',
        'angular2-in-memory-web-api': 'node_modules/angular2-in-memory-web-api',
        'rxjs': 'node_modules/rxjs',

        '@angular2-material/core': 'node_modules/@angular2-material/core',
        '@angular2-material/button': 'node_modules/@angular2-material/button',
        '@angular2-material/card': 'node_modules/@angular2-material/card',
        '@angular2-material/slide-toggle': 'node_modules/@angular2-material/slide-toggle',
        '@angular2-material/toolbar': 'node_modules/@angular2-material/toolbar'


    };

    // packages tells the System loader how to load when no filename and/or no extension
    var packages = {
        'app': {
            main: 'main.js',
            defaultExtension: 'js'
        },
        'rxjs': {
            defaultExtension: 'js'
        },

        'angular2-in-memory-web-api': {
            main: 'index.js',
            defaultExtension: 'js'
        },



        '@angular2-material/core': {
            main: 'core.js'
        },
        '@angular2-material/card': {
            main: 'card.js'
        },
        '@angular2-material/button': {
            main: 'button.js'
        },
        '@angular2-material/toolbar': {
            main: 'toolbar.js'
        },
        '@angular2-material/slide-toggle': {
            main: 'slide-toggle.js'
        }



    };

    var ngPackageNames = [
        'common',
        'compiler',
        'core',
        'forms',
        'http',
        'platform-browser',
        'platform-browser-dynamic',
        'router',
        'router-deprecated',
        'upgrade',
    ];

    // Individual files (~300 requests):
    function packIndex(pkgName) {
        packages['@angular/' + pkgName] = {
            main: 'index.js',
            defaultExtension: 'js'
        };
    }

    // Bundled (~40 requests):
    function packUmd(pkgName) {
        packages['@angular/' + pkgName] = {
            main: '/bundles/' + pkgName + '.umd.js',
            defaultExtension: 'js'
        };
    }

    // Most environments should use UMD; some (Karma) need the individual index files
    var setPackageConfig = System.packageWithIndex ? packIndex : packUmd;

    // Add package entries for angular packages
    ngPackageNames.forEach(setPackageConfig);

    // No umd for router yet
    packages['@angular/router'] = {
        main: 'index.js',
        defaultExtension: 'js'
    };

    var config = {
        map: map,
        packages: packages
    };

    System.config(config);

})(this);

@jelbourn
Copy link
Member

Without using the angular CLI, it's up to you to both copy the files to the appropriate directory for serving configure whatever module loader you're using to be able to then load those files. These are going to be specific to your app / build process / environment, so there's no universal "this is what you do".

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants