注意:我不使用 Angular-Cli
其他angular2 -material 组件似乎需要 OverlayModule。
zone.js:355 未处理的承诺拒绝:./AppComponent 类 AppComponent 中的错误 - 内联模板:2:2 原因是:没有覆盖的提供者!; 区域:; 任务:Promise.then;价值:
我已经从 angular2-material 安装了所有软件包。
sytemjs.config.js
map: {
// our app is within the app folder
app: 'dist',
...
...
'@angular2-material/core': 'npm:@angular2-material/core/core.umd.js',
'@angular2-material/button': 'npm:@angular2-material/button/button.umd.js',
'@angular2-material/menu': 'npm:@angular2-material/menu/menu.umd.js',
'@angular2-material/icon': 'npm:@angular2-material/icon/icon.umd.js',
_____________________________________________________________________
/*>>>>> DO I NEED TO MAP ANYTHING FOR OVERLAY HERE? <<<<<< */
______________________________________________________________________
// other libraries
'rxjs': 'npm:rxjs',
'angular2-in-memory-web-api': 'npm:angular2-in-memory-web-api',
},
我将sharedModule用于 angular2-material 组件,以便它们随处可用。
shared.module.ts
import {MdButtonModule } from '@angular2-material/button';
import {MdIconModule} from '@angular2-material/icon';
import {MdMenuModule} from '@angular2-material/menu';
import {MdIconRegistry} from '@angular2-material/icon';
@NgModule({
imports: [ CommonModule ],
declarations: [],
exports: [ CommonModule,MdButtonModule,MdMenuModule,MdIconModule],
})
export class SharedModule {
static forRoot(): ModuleWithProviders {
return {
ngModule: SharedModule,
providers: [ MdIconRegistry ] //>>>>> DO I NEED TO ADD ANYTHING HERE ??
};
}
}
应用模块.ts
@NgModule({
imports: [ BrowserModule,SharedModule.forRoot()],
...
})
HTML:
<button md-icon-button [md-menu-trigger-for]="menu">
<md-icon>more_vert</md-icon>
</button>
<md-menu #menu="mdMenu">
<button md-menu-item> Refresh </button>
<button md-menu-item> Settings </button>
<button md-menu-item> Help </button>
<button md-menu-item disabled> Sign Out </button>
</md-menu>
<button md-raised-button>Button</button>