gpt4 book ai didi

angular - Angular2 中的 Material 设计组件 "is not a known element"

转载 作者:太空狗 更新时间:2023-10-29 16:48:07 24 4
gpt4 key购买 nike

我有一个混合的 Angular1 和 Angular2 应用程序。在我路由到的 Angular2 组件之一中,我想使用 Material Design 按钮。

当我像这样在模板中插入一个按钮时 <md-button>foo</md-button>应用程序开始崩溃并显示此控制台消息

Error: Template parse errors:
'md-button' is not a known element:
1. If 'md-button' is an Angular component, then verify that it is part of this module.
2. If 'md-button' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schemas' of this component to suppress this message. ("<h1>Job</h1>[ERROR ->]<md-button>material</md-button>"): JobComponent@0:12
at TemplateParser.parse (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:8321:21)

所以,这听起来像是消息中的情况 1,但我已经尝试了 this answer 中给出的建议。添加MdButtonimports我的属性(property)NgModule (已包含 MaterialModule.forRoot(),如 the documentation 所建议),但如果我这样做,整个应用程序将在控制台中变为空白且不会出现错误。

这里是一些相关的代码

import { UIRouterModule } from "ui-router-ng2";
import { Ng1ToNg2Module, uiRouterNgUpgrade } from "ui-router-ng1-to-ng2";

import { MaterialModule, MdButton } from '@angular/material';


const upgradeAdapter: UpgradeAdapter = new UpgradeAdapter(
forwardRef(() => XamFlowNg2Module));

uiRouterNgUpgrade.setUpgradeAdapter(upgradeAdapter);

angular.module("xamFlow")
.factory("consoleService",
upgradeAdapter.downgradeNg2Provider(ConsoleService));


/*
* Expose our ng1 content to ng2
*/
upgradeAdapter.upgradeNg1Provider("restService");

@NgModule({
declarations: [
JobComponent,
],
entryComponents: [
// Components that are routed to must be listed here, otherwise you'll get "No Component Factory"
JobComponent,
],
imports: [
CommonModule,
BrowserModule,
FormsModule,
HttpModule,
Ng1ToNg2Module,
MaterialModule.forRoot()
],
providers: [
ConsoleService,
ImageService
]
})
class MyModule { }


upgradeAdapter.bootstrap(document.body, ["myApp"]);

最佳答案

应该是

<button md-button>foo</button>   

<button md-raised-button>foo</button>

关于angular - Angular2 中的 Material 设计组件 "is not a known element",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40195457/

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