Angular 2 RC 6 Material 2 Alpha 8 不工作
Angular 2 RC 6 Material 2 Alpha 8 Not Working
我最近将我的项目升级到 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
已修复!如果有人仍在努力在您的项目中制作 Angular 2 RC 6 Material 2 Alpha 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);
AppModule
进口
//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
]
我将 Material 2 与 'official' systemjs.config.js
文件一起使用,但无法使用 .js
桶。
所以我继续将它们映射到 .umd
文件,例如
map: {
...
'@angular2-material/button': 'npm:@angular2-material/button/button.umd.js',
'@angular2-material/card': 'npm:@angular2-material/card/card.umd.js',
'@angular2-material/checkbox': 'npm:@angular2-material/checkbox/checkbox.umd.js',
...
}
并删除了 packages
部分中的相关条目。这对我有用。
我最近将我的项目升级到 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
已修复!如果有人仍在努力在您的项目中制作 Angular 2 RC 6 Material 2 Alpha 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);
AppModule
进口
//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
]
我将 Material 2 与 'official' systemjs.config.js
文件一起使用,但无法使用 .js
桶。
所以我继续将它们映射到 .umd
文件,例如
map: {
...
'@angular2-material/button': 'npm:@angular2-material/button/button.umd.js',
'@angular2-material/card': 'npm:@angular2-material/card/card.umd.js',
'@angular2-material/checkbox': 'npm:@angular2-material/checkbox/checkbox.umd.js',
...
}
并删除了 packages
部分中的相关条目。这对我有用。