我最近将我的项目升级到了angular2rc6和material 2.0.0-alpha.8-1,但它不起作用,有人能告诉我这里遗漏了什么吗?有人可以分享一个工作与角度2钢筋混凝土6和材料2.0.0-阿尔法.8-1?
我的package.json中有以下包:

"@angular2-material/button": "2.0.0-alpha.8-1",
"@angular2-material/button-toggle": "2.0.0-alpha.8-1",
"@angular2-material/card": "2.0.0-alpha.8-1",
"@angular2-material/checkbox": "2.0.0-alpha.8-1",
"@angular2-material/core": "2.0.0-alpha.8-1",
"@angular2-material/grid-list": "2.0.0-alpha.8-1",
"@angular2-material/icon": "2.0.0-alpha.8-1",
"@angular2-material/input": "2.0.0-alpha.8-1",
"@angular2-material/list": "2.0.0-alpha.8-1",
"@angular2-material/menu": "2.0.0-alpha.8-1",
"@angular2-material/progress-bar": "2.0.0-alpha.8-1",
"@angular2-material/progress-circle": "2.0.0-alpha.8-1",
"@angular2-material/radio": "2.0.0-alpha.8-1",
"@angular2-material/sidenav": "2.0.0-alpha.8-1",
"@angular2-material/slider": "2.0.0-alpha.8-1",
"@angular2-material/slide-toggle": "2.0.0-alpha.8-1",
"@angular2-material/tabs": "2.0.0-alpha.8-1",
"@angular2-material/toolbar": "2.0.0-alpha.8-1",
"@angular2-material/tooltip": "2.0.0-alpha.8-1",

在appmodule中,我首先导入了以下必需的模块:
import { MdCoreModule } from '@angular2-material/core/core';
import { MdCheckboxModule } from '@angular2-material/checkbox/checkbox';
import { MdProgressBarModule } from '@angular2-material/progress-bar/progress-bar';
import { MdRadioModule, MdUniqueSelectionDispatcher } from '@angular2-material/radio/radio';
import { MdSlideToggleModule } from '@angular2-material/slide-toggle/slide-toggle';
import { MdTabsModule } from '@angular2-material/tabs/tabs';

然后在导入列表中添加以下内容:
imports: [
    ....
    // Material Design
    MdCoreModule.forRoot(),
    MdCheckboxModule.forRoot(),
    MdRadioModule.forRoot(),
    MdSlideToggleModule.forRoot(),
    MdTabsModule.forRoot(),
    MdProgressBarModule.forRoot(),
    ....
],

在提供程序中:
providers: [
        MdUniqueSelectionDispatcher
]

在我的systemjs配置文件中,我有:
var map = {
    '@angular': 'node_modules/@angular',
    '@angular2-material': 'node_modules/@angular2-material',

    'rxjs': 'node_modules/rxjs',

    'app': 'content/app',
    "angular2-masonry": "node_modules/angular2-masonry"
};

var paths = {
        "masonry-layout": "node_modules/masonry-layout/dist/masonry.pkgd.js"
    };

var packages = {
        'app': { main: 'main.js', defaultExtension: 'js' },
        'rxjs': { defaultExtension: 'js' },
        'angular2-masonry': { defaultExtension: 'js', main: "index" }
    };


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

angularPackages.forEach(function (name) {
    packages['@angular/' + name] = {
        format: 'cjs',
        main: 'bundles/' + name + '.umd.js', defaultExtension: 'js'
    };
});

var materialComponents = [
        'core',
        'button',
        'card',
        'checkbox',
        'grid-list',
        'icon',
        'input',
        'list',
        'progress-bar',
        'progress-circle',
        'radio',
        'sidenav',
        'slide-toggle',
        'tabs',
        'toolbar'
    ];

    materialComponents.forEach(function (name) {
        packages[("@angular2-material/" + name)] = {
            format: 'cjs',
            main: name + '.umd.js',
            defaultExtension: 'js'
        };
    });

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

    System.config(config);

下面是运行应用程序时控制台上显示的错误消息:
43 Error: SyntaxError: Unexpected token import
at Object.eval (http://localhost:57196/content/app/app.module.js:16:14)
at eval (http://localhost:57196/content/app/app.module.js:328:4)
at eval (http://localhost:57196/content/app/app.module.js:329:3)
Evaluating http://localhost:57196/node_modules/@angular2-material/core/core.js
Evaluating http://localhost:57196/content/app/app.module.js
Evaluating http://localhost:57196/content/app/main.js
Error loading http://localhost:57196/content/app/main.js

最佳答案

把它修好了!如果有人仍在努力使角2钢筋混凝土6材料2阿尔法8运行在您的项目,下面的配置可能会工作。
下面是我的systemjs配置文件

(function (global) {
    var map = {
        //angular
        '@angular': 'node_modules/@angular',
        '@angular2-material': 'node_modules/@angular2-material',
        'rxjs': 'node_modules/rxjs',

        'app': 'content/app',

        //thirdparty
        "angular2-masonry": "node_modules/angular2-masonry",
    };

    var paths = {
        "masonry-layout": "node_modules/masonry-layout/dist/masonry.pkgd.js"
    };

    var packages = {
        'app': { main: 'main.js', defaultExtension: 'js' },
        'rxjs': { defaultExtension: 'js' },
        "angular2-masonry": { defaultExtension: 'js', main: "index" }
    };

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

    angularPackages.forEach(function (name) {
        packages['@angular/' + name] = {
            format: 'cjs',
            main: 'bundles/' + name + '.umd.js',
            defaultExtension: 'js'
        };
    });

    var materialComponents = [
        'checkbox',
        'core',
        'progress-bar',
        'progress-circle',
        'radio',
        'sidenav',
        'slide-toggle',
        'tabs'
    ];

    materialComponents.forEach(function (name) {
        packages[("@angular2-material/" + name)] = {
            format: 'cjs',
            main: name + '.umd.js',
            defaultExtension: 'js'
        };
    });

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

    System.config(config);

})(this);

附加模块
进口
//angular
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { Http, XHRBackend, HttpModule, RequestOptions, JsonpModule } from '@angular/http';
import { NgModule } from '@angular/core';

//material
import { MdCheckboxModule } from '@angular2-material/checkbox';
import { MdProgressBarModule } from '@angular2-material/progress-bar';
import { MdRadioModule, MdUniqueSelectionDispatcher } from '@angular2-material/radio';
import { MdSlideToggleModule } from '@angular2-material/slide-toggle';
import { MdTabsModule } from '@angular2-material/tabs';

NGmodule中的导入
@NgModule({
    imports: [
        //angular
        BrowserModule,
        FormsModule,
        HttpModule,
        JsonpModule,
        ReactiveFormsModule,
        routing,

        //material
        MdCheckboxModule.forRoot(),
        MdRadioModule.forRoot(),
        MdSlideToggleModule.forRoot(),
        MdTabsModule.forRoot(),
        MdProgressBarModule.forRoot(),
        MdProgressBarModule.forRoot()
//.....
    ],

如果你在用收音机
providers: [
        MdUniqueSelectionDispatcher
]

关于angular - Angular 2 RC 6 Material 2 Alpha 8不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39334852/

10-16 19:07