我最近将我的项目升级到 Angular 2 RC 6 和 Material 2.0.0-alpha.8-1 但它不起作用,谁能指导我在这里缺少什么?任何人都可以与 Angular 2 RC 6 和 Material 2.0.0-alpha.8-1 分享一个工作的 plunker 吗?
我的 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