草庐IT

关于 angular:Failed: Template parse errors: \\’mat-card-title\\’ is not a known element

codeneng 2023-03-28 原文

Failed: Template parse errors: 'mat-card-title' is not a known element

两个月前我开始使用 Angular,我设计了一个应用程序并进行了 ng 测试,我遇到了这个错误:

失败:模板解析错误:
'mat-card-title' 不是已知元素:
1. 如果"mat-card-title"是一个 Angular 组件,那么验证它是这个模块的一部分。
2. 如果 'mat-card-title' 是一个 Web 组件,则将 'CUSTOM_ELEMENTS_SCHEMA' 添加到该组件的 '@NgModule.schemas' 以禁止显示此消息。
我不明白我的代码中有什么不起作用。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { NgModule } from '@angular/core';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { HeroService } from './hero.service';

import { AngularFireAuthModule } from '@angular/fire/auth';
import { AngularFireModule } from '@angular/fire';
import { AngularFirestoreModule } from '@angular/fire/firestore';
import { AngularFireStorageModule } from '@angular/fire/storage';
import { AngularMaterialModule } from './angular-material/angular-material.module';

import { environment } from 'src/environments/environment';

import { FormsModule } from '@angular/forms';

import { ToastrModule } from 'ngx-toastr';

import { HeroesListComponent } from './heroes-list/heroes-list.component';
import { HeroDetailComponent } from './hero-detail/hero-detail.component';
import { HeroSearchComponent } from './hero-search/hero-search.component';
import { HeroTableComponent } from './hero-table/hero-table.component';
import { LoginComponent } from './login/login.component';
import { NavbarHeroesComponent } from './navbar-heroes/navbar-heroes.component';
import { AddHeroesComponent } from './add-heroes/add-heroes.component';
import { HeroGridComponent } from './hero-grid/hero-grid.component';

import { FlexLayoutModule } from '@angular/flex-layout';



@NgModule({
declarations: [
  AppComponent,
  LoginComponent
],
imports: [
  BrowserModule,
  AppRoutingModule,
  BrowserAnimationsModule,
  FormsModule,
  AngularFireModule.initializeApp( environment.firebaseConfig ),
  AngularFirestoreModule,
  FlexLayoutModule,
  AngularFireAuthModule,
  AngularFireStorageModule,
  ToastrModule.forRoot(),
  AngularMaterialModule
],
providers: [
  HeroService
],
bootstrap: [AppComponent]
})
export class AppModule { }

这是 AngularMaterialModule

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
 import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { CommonModule } from '@angular/common';

import {
  MatButtonModule,
  MatTableModule,
  MatIconModule,
  MatFormFieldModule,
  MatSelectModule,
  MatInputModule,
  MatRadioModule,
  MatToolbarModule,
  MatCardModule,
  MatGridListModule,
  MatCheckboxModule,
 } from '@angular/material';

const moduleAngularMaterial = [
  MatButtonModule,
  MatIconModule,
  MatFormFieldModule,
  MatSelectModule,
  MatInputModule,
  MatTableModule,
  MatCheckboxModule,
  MatRadioModule,
  MatToolbarModule,
  MatCardModule,
  MatGridListModule
];


@NgModule({
  declarations: [
  ],
  imports: [
    moduleAngularMaterial,
    CommonModule
  ],
  exports: [
    moduleAngularMaterial
  ],
})
export class AngularMaterialModule { }

  • 进口:[...moduleAngularMaterial,CommonModule]


当组件模块是:

  • 未在声明并打算使用的模块中导入
  • 不从声明使用 Angular 组件的组件的 SharedModule 重新导出。
  • 根据您的项目场景,可以选择:

  • 在声明和打算使用的同一模块中导入 mat 组件模块,或
  • 从 [YourCustom]Module 重新导出 mat ui 组件模块,该模块为 Angular 导入 mat Ui 模块。
    • 尝试仅将其导入您的根模块或您的自定义模块
    • 大家好,我解决了我只需要导入我在规范文件中创建的angular材料模块的问题
    • @Intelligence 任何其他解决方案。我现在被困在测试中。


    在 Angular 文档中参见:

    Angular Material 卡片测试的 API 参考

    import {MatCardHarness} from '@angular/material/card/testing';

    这可能是你在测试中卡住的原因。


    传播数组值

    1
    imports: [...moduleAngularMaterial, CommonModule]

    有关关于 angular:Failed: Template parse errors: \\’mat-card-title\\’ is not a known element的更多相关文章

    1. ruby-on-rails - 错误 : Error installing pg: ERROR: Failed to build gem native extension - 2

      我克隆了一个rails仓库,我现在正尝试捆绑安装背景:OSXElCapitanruby2.2.3p173(2015-08-18修订版51636)[x86_64-darwin15]rails-v在您的Gemfile中列出的或native可用的任何gem源中找不到gem'pg(>=0)ruby​​'。运行bundleinstall以安装缺少的gem。bundleinstallFetchinggemmetadatafromhttps://rubygems.org/............Fetchingversionmetadatafromhttps://rubygems.org/...Fe

    2. ruby-on-rails - 关于 Ruby 的一般问题 - 2

      我在我的rails应用程序中安装了来自github.com的acts_as_versioned插件,但有一段代码我不完全理解,我希望有人能帮我解决这个问题class_eval我知道block内的方法(或任何它是什么)被定义为类内的实例方法,但我在插件的任何地方都找不到定义为常量的CLASS_METHODS,而且我也不确定是什么here,并且有问题的代码从lib/acts_as_versioned.rb的第199行开始。如果有人愿意告诉我这里的内幕,我将不胜感激。谢谢-C 最佳答案 这是一个异端。http://en.wikipedia

    3. ruby-on-rails - gem install rmagick -v 2.13.1 错误 Failed to build gem native extension on Mac OS 10.9.1 - 2

      我已经通过提供MagickWand.h的路径尝试了一切,我安装了命令工具。谁能帮帮我?$geminstallrmagick-v2.13.1Buildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingrmagick:ERROR:Failedtobuildgemnativeextension./Users/ghazanfarali/.rvm/rubies/ruby-1.8.7-p357/bin/rubyextconf.rbcheckingforRubyversion>=1.8.5...yescheckingfor/

    4. ruby 单元测试 : run some code after each failed test - 2

      在Test::Unit中的ruby​​单元测试断言失败后,在执行teardown之前,是否有一些简洁优雅的方法来立即执行我的代码?我正在做一些自动化的GUI测试,并希望在出现问题后立即截图。 最佳答案 如果您使用的是1.9,请不要使用Test::Unit::TestCase作为您的基类。对其进行子类化并覆盖#run_test以进行救援,截取屏幕截图并重新提出:classMyAbstractTestCase或者,我认为这实际上是最简洁的方法,您可以使用before_teardownHook:classMyTestCase这不适用于1.

    5. ruby-on-rails - 致命 : Peer authentication failed for user "rails" - 2

      我正在尝试运行rakedb:create在DigitalOcean服务器上使用postgresql。但是,它返回错误Peerauthenticationfailedforuser"rails",引用config/database.yml登录凭据的存储位置奇怪的是,当我通过SSH登录服务器时,这些凭据以纯文本形式显示给我。我都试过了密码以纯文本形式显示给我,同样的事情发生了。环境在生产中,我必须手动强制执行,因为应用程序在启动时正在开发中并强制它在config/environments.rb中更改不工作。如果我不得不猜测,我可能会说环境中发生了一些有趣的事情,因为DigitalOcean

    6. ruby - 我怎样才能更好地了解/了解更多关于 Ruby 的知识? - 2

      按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visitthehelpcenter指导。关闭9年前。我最近开始学习Ruby,这是我的第一门编程语言。我对语法感到满意,并且我已经完成了许多只教授相同基础知识的教程。我已经写了一些小程序(包括我自己的数组排序方法,在有人告诉我谷歌“冒泡排序”之前我认为它非常聪明),但我觉得我需要尝试更大更难的东西来理解更多关于Ruby.关于如何执行此操作的任何想法?

    7. ruby-on-rails - 32651 :ERROR comparison of Float with Float failed ruby - 2

      我是Rails的新手,我遇到了一个错误,但我似乎找不到问题所在。这是日志:[32651:ERROR]2012-10-0913:46:52::comparisonofFloatwithFloatfailed[32651:ERROR]2012-10-0913:46:52::/home/sunny/backend/lib/analytics/lifetime.rb:45:in`each'/home/sunny/backend/lib/analytics/lifetime.rb:45:in`max'/home/sunny/backend/lib/analytics/lifetime.rb:45

    8. ruby - 关于 Ruby 中 Dir[] 和 File.join() 的混淆 - 2

      我在Ruby中遇到了一个关于Dir[]和File.join()的简单程序,blobs_dir='/path/to/dir'Dir[File.join(blobs_dir,"**","*")].eachdo|file|FileUtils.rm_rf(file)ifFile.symlink?(file)我有两个困惑:首先,File.join(@blobs_dir,"**","*")中的第二个和第三个参数是什么意思?其次,Dir[]在Ruby中有什么用?我只知道它等价于Dir.glob(),但是,我对Dir.glob()确实不是很清楚。 最佳答案

    9. elasticsearch源码关于TransportSearchAction【阶段三】 - 2

      1.回顾.TransportServicepublicclassTransportServiceextendsAbstractLifecycleComponentTransportService:方法:1publicfinalTextendsTransportResponse>voidsendRequest(finalTransport.Connectionconnection,finalStringaction,finalTransportRequestrequest,finalTransportRequestOptionsoptions,TransportResponseHandlerT>

    10. 关于Qt程序打包后运行库依赖的常见问题分析及解决方法 - 2

      目录一.大致如下常见问题:(1)找不到程序所依赖的Qt库version`Qt_5'notfound(requiredby(2)CouldnotLoadtheQtplatformplugin"xcb"in""eventhoughitwasfound(3)打包到在不同的linux系统下,或者打包到高版本的相同系统下,运行程序时,直接提示段错误即segmentationfault,或者Illegalinstruction(coredumped)非法指令(4)ldd应用程序或者库,查看运行所依赖的库时,直接报段错误二.问题逐个分析,得出解决方法:(1)找不到程序所依赖的Qt库version`Qt_5'

    随机推荐