gpt4 book ai didi

angular - 使用 mdIcon 时从控制台获取错误

转载 作者:太空狗 更新时间:2023-10-29 17:08:43 27 4
gpt4 key购买 nike

当我使用 mdIcon 时,Angular 抛出错误。下面是代码:

import {Component} from '@angular/core';
import {MdIcon} from '@angular2-material/icon';
@Component({
selector: 'my-app',
template: `
<md-toolbar>
<md-icon class="demo-toolbar-icon">menu</md-icon>
<span>Default Toolbar</span>

<span class="demo-fill-remaining"></span>

<md-icon>code</md-icon>
</md-toolbar>`,
directives: [MdIcon,MdToolbar],

})
export class AppComponent {}

错误:

ORIGINAL EXCEPTION: No provider for MdIconRegistry! Error: DI Exception at NoProviderError.BaseException [as constructor] (exceptions.ts:14) at NoProviderError.AbstractProviderError [as constructor] (reflective_exceptions.ts:53) at new NoProviderError (reflective_exceptions.ts:85) at ReflectiveInjector_._throwOrNull (reflective_injector.ts:844) at ReflectiveInjector_._getByKeyDefault (reflective_injector.ts:873) at ReflectiveInjector_._getByKey (reflective_injector.ts:835) at ReflectiveInjector_.get (reflective_injector.ts:632) at ElementInjector.get (element_injector.ts:19) at DebugAppView._View_AppComponent0.createInternal (AppComponent.template.js:141) at DebugAppView.AppView.create (view.ts:110)

任何人都可以帮我看看我做错了什么吗?

最佳答案

使用 Material alpha 8-4 更新 2.0.0 版本:

您需要将 MdIconRegistry 作为提供程序包含在您的 app.modules.ts 文件中。这是一个功能示例:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';

import { MdButtonModule } from '@angular2-material/button';
import { MdButtonToggleModule } from '@angular2-material/button-toggle';
import { MdCardModule } from '@angular2-material/card';
import { MdCheckboxModule } from '@angular2-material/checkbox';
import { MdGridListModule } from '@angular2-material/grid-list';
import { MdIconModule, MdIconRegistry } from '@angular2-material/icon';
import { MdInputModule } from '@angular2-material/input';
import { MdListModule } from '@angular2-material/list';
import { MdMenuModule } from '@angular2-material/menu';
import { MdProgressBarModule } from '@angular2-material/progress-bar';
import { MdProgressCircleModule } from '@angular2-material/progress-circle';
import { MdRadioModule } from '@angular2-material/radio';
import { MdSidenavModule } from '@angular2-material/sidenav';
import { MdSliderModule } from '@angular2-material/slider';
import { MdSlideToggleModule } from '@angular2-material/slide-toggle';
import { MdTabsModule } from '@angular2-material/tabs';
import { MdToolbarModule } from '@angular2-material/toolbar';
import { MdTooltipModule } from '@angular2-material/tooltip';

import { AppComponent } from './app.component';


@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule,

MdButtonModule,
MdButtonToggleModule,
MdCardModule,
MdCheckboxModule,
MdGridListModule,
MdIconModule,
MdInputModule,
MdListModule,
MdMenuModule,
MdProgressBarModule,
MdProgressCircleModule,
MdRadioModule,
MdSidenavModule,
MdSliderModule,
MdSlideToggleModule,
MdTabsModule,
MdToolbarModule,
MdTooltipModule
],
providers: [
MdIconRegistry
],
bootstrap: [AppComponent]
})
export class AppModule { }

如果您想使用 md-slide-toggle 和 md-slider 模块,请不要忘记安装 hammerjs + typings 并将 import 'hammerjs'; 添加到您的 main.ts 文件中。

关于angular - 使用 mdIcon 时从控制台获取错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37118593/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com