gpt4 book ai didi

angular - 在 Angular 2 应用程序中使用 Material 单选按钮的问题

转载 作者:太空狗 更新时间:2023-10-29 18:13:06 26 4
gpt4 key购买 nike

平台:Ubuntu 14.0.1NPM 版本:4.6.1

我有一个 Angular 2 应用程序,我试图在其中使用 Material 单选按钮。我已经使用以下命令安装了那些:

npm i @angular2-material/radio

我在模块中添加了以下代码:

import { Component } from '@angular/core';
import { FormControl, FormGroup, FormBuilder, Validators } from '@angular/forms';
import { Router } from '@angular/router';
import { MdRadioModule } from '@angular2-material/radio';

以下是 .html 文件的内容(中断):

<md-radio-group>
<md-radio-button value="1">Option 1</md-radio-button>
<md-radio-button value="2">Option 2</md-radio-button>
</md-radio-group>

当我运行应用程序时,我在浏览器的控制台中收到以下错误,我的应用程序在那里中断:

nhandled Promise rejection: Template parse errors:
'md-radio-group' is not a known element:
1. If 'md-radio-group' is an Angular component, then verify that it is part of this module.
2. If 'md-radio-group' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schemas' of this component to suppress this message. (" <md-radio-button value="2">Option 2</md-radio-button>
</md-radio-group>-->
[ERROR ->]<md-radio-group></md-radio-group>
<div class="page-card-separator">&nbsp;</div>
"): AddProviderComponent@35:12 ; Zone: <root> ; Task: Promise.then ; Value: Error: Template parse errors:
'md-radio-group' is not a known element:
1. If 'md-radio-group' is an Angular component, then verify that it is part of this module.
2. If 'md-radio-group' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schemas' of this component to suppress this message. (" <md-radio-button value="2">Option 2</md-radio-button>
</md-radio-group>-->
[ERROR ->]<md-radio-group></md-radio-group>
<div class="page-card-separator">&nbsp;</div>
"): AddProviderComponent@35:12
at TemplateParser.parse (compiler.umd.js:8502)
at RuntimeCompiler._compileTemplate (compiler.umd.js:16882)
at eval (compiler.umd.js:16805)
at Set.forEach (<anonymous>)
at compile (compiler.umd.js:16805)
at ZoneDelegate.invoke (zone.js?1505985812318:192)
at Zone.run (zone.js?1505985812318:85)
at zone.js?1505985812318:451
at ZoneDelegate.invokeTask (zone.js?1505985812318:225)
at Zone.runTask (zone.js?1505985812318:125) Error: Template parse errors:

最佳答案

首先安装@angular/material@angular/cdk,然后在app.module.ts文件中导入相关包:

import { MatRadioModule } from '@angular/material';

关于angular - 在 Angular 2 应用程序中使用 Material 单选按钮的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46340447/

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