- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
目前我有一个 angular component x.component.html
包含以下内容(使用 angular material ):
<div class="example-container mat-elevation-z8">
<div class="example-header">
<mat-form-field>
<input matInput (keyup)="applyFilter($event.target.value)" placeholder="Filter">
</mat-form-field>
</div>
<mat-table #table [dataSource]="dataSource">
<ng-container matColumnDef="farbeKey">
<mat-header-cell *matHeaderCellDef> farbeKey </mat-header-cell>
<mat-cell *matCellDef="let element"> {{element.farbeKey}} </mat-cell>
</ng-container>
....
此外,我还有如下所示的组件 x.component.ts
:
import { BrowserModule } from '@angular/platform-browser';
import { Component, OnInit } from '@angular/core';
import { User } from '../models/user.model';
import { OrgtService } from './orgt.service';
@Component({
selector: 'x-component',
styleUrls: ['x.component.css'],
templateUrl: 'x.component.html',
})
export class XComponent implements OnInit {
users: User[] = []
constructor(private xService: XService) {
}
displayedColumns = ['c1', 'c2', 'c3', 'c4'];
dataSource = new MatTableDataSource(this.users);
applyFilter(filterValue: string) {
filterValue = filterValue.trim(); // Remove whitespace
filterValue = filterValue.toLowerCase(); // MatTableDataSource defaults to lowercase matches
this.dataSource.filter = filterValue;
}
public ngOnInit() {
this.xService.getUsers()
.subscribe(
(users) => {
this.users = users;
}
);
}
}
但问题是,如果尝试在浏览器中访问它,我会收到以下错误消息(这只是摘录):
Uncaught Error: Bootstrap's JavaScript requires jQuery
at scripts.bundle.js:8
(anonymous) @ scripts.bundle.js:8
compiler.js:485 Uncaught Error: Template parse errors:
'mat-form-field' is not a known element:
1. If 'mat-form-field' is an Angular component, then verify that it is part of this module.
2. If 'mat-form-field' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("
<div class="example-header">
[ERROR ->]<mat-form-field>
<input matInput (keyup)="applyFilter($event.target.value)" placeholder="Filter"): ng:///AppModule/OrgtComponent.html@3:4
Can't bind to 'dataSource' since it isn't a known property of 'mat-table'.
1. If 'mat-table' is an Angular component and it has 'dataSource' input, then verify that it is part of this module.
2. If 'mat-table' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. ("
</div>
这是我的 package.json
文件:
{
"name": "portal-app",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve --proxy-config proxy.config.json",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "^5.0.0",
"@angular/cdk": "^5.2.2",
"@angular/common": "^5.0.0",
"@angular/compiler": "^5.0.0",
"@angular/core": "^5.0.0",
"@angular/forms": "^5.0.0",
"@angular/http": "^5.0.0",
"@angular/material": "^5.2.2",
"@angular/platform-browser": "^5.0.0",
"@angular/platform-browser-dynamic": "^5.0.0",
"@angular/router": "^5.0.0",
"bootstrap": "^3.3.7",
"core-js": "^2.4.1",
"rxjs": "^5.5.2",
"zone.js": "^0.8.14"
},
"devDependencies": {
"@angular/cli": "1.6.3",
"@angular/compiler-cli": "^5.0.0",
"@angular/language-service": "^5.0.0",
"@types/jasmine": "~2.5.53",
"@types/jasminewd2": "~2.0.2",
"@types/node": "~6.0.60",
"codelyzer": "^4.0.1",
"jasmine-core": "~2.6.2",
"jasmine-spec-reporter": "~4.1.0",
"karma": "~1.7.0",
"karma-chrome-launcher": "~2.1.1",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.1.2",
"ts-node": "~3.2.0",
"tslint": "~5.7.0",
"typescript": "~2.4.2"
}
}
如果我理解正确,我不知何故/某处遗漏了 mat-...
标签的定义,但我不知道我需要在哪里放置什么样的定义?有人能稍微启发一下吗?
更新 (1):安装 jquery 并更改 .angular-cli.json
文件后,错误消息已按预期更改以消除 JQuery 问题,如下所示:
发现错误:模板解析错误:'mat-form-field' 不是已知元素:1. 如果“mat-form-field”是一个 Angular 组件,那么验证它是这个模块的一部分。2. 如果“mat-form-field”是一个 Web 组件,则将“CUSTOM_ELEMENTS_SCHEMA”添加到该组件的“@NgModule.schemas”以抑制此消息。 ("
<div class="example-header">
[ERROR ->]<mat-form-field>
<input matInput (keyup)="applyFilter($event.target.value)" placeholder="Filter"): ng:///AppModule/OrgtComponent.html@3:4
Can't bind to 'dataSource' since it isn't a known property of 'mat-table'.
1. If 'mat-table' is an Angular component and it has 'dataSource' input, then verify that it is part of this module.
2. If 'mat-table' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. ("
</div>
我还根据 Juan 的建议添加了导入。
更新 (2):集成每个答案后,我的应用程序启动并编译没有任何问题。现在我得到以下信息:
ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'x'
Error: Cannot match any routes. URL Segment: 'x'
更新 (3):
所以在像这样修复 app.routing.module.ts
之后:
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { UserComponent } from './user/user.component';
import {AddUserComponent} from './user/add-user.component';
import { XComponent} from './x/x.component';
const routes: Routes = [
{ path: 'users', component: UserComponent },
{ path: 'add', component: AddUserComponent },
{ path: 'x', component: XComponent }
];
@NgModule({
imports: [
RouterModule.forRoot(routes)
],
exports: [
RouterModule
],
declarations: []
})
export class AppRoutingModule { }
我又向前迈进了一步,得到了这个:
ERROR Error: Uncaught (in promise): Error: StaticInjectorError[XService]:
StaticInjectorError[XService]:
NullInjectorError: No provider for XService!
Error: StaticInjectorError[XService]:
StaticInjectorError[XService]:
NullInjectorError: No provider for XService
最佳答案
您需要在 app.module.ts 中导入以下内容:
import {MatInputModule} from '@angular/material/input';
import {MatTableModule} from '@angular/material/table';
import {FormsModule} from '@angular/forms';
在你的 x.component.ts 中:
import {MatTableDataSource} from '@angular/material';
关于javascript - “mat-form-field”不是已知元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49004513/
我已经彻底搜索过,但没有找到直接的答案。 将 opencv 矩阵 (cv::Mat) 作为参数传递给函数,我们传递的是智能指针。我们对函数内部的输入矩阵所做的任何更改也会改变函数范围之外的矩阵。 我读
是否可以有一个垫子分隔线(一条水平线分隔两个垫子选项)? 我试过: Cars Volvo Saab Mercedes Audi
使用的浏览器 - Chrome 67.0.3396.99 我创建了一个 DialogsModule它有一个组件 ConfirmDialog.component.ts使用以下模板 confirm-dia
我正在尝试使用 mat-toolbar 但出现错误: mat-menu.component.html: Responsive Navigation Menu I
我正在创建 angular 7 网络应用程序,并使用一个 mat-select 下拉菜单和一个 mat-paginator。现在我隐藏 mat-select 向下箭头。 Here is the mat
在我的应用程序中,我有一个通过引用接收 cv::Mat 对象的函数。这是函数的声明: void getChains(cv::Mat &img,std::vector &chains,cv::
我使用了独立的 EMA (1.5.0) 和 eclipse 插件(在 eclipse 4.5 中)来分析我的堆转储。 我想查看任何无法访问的对象信息,我已尝试在我的首选项和命令行选项 -keep_un
我是 flex 的新手,我的垫子 table 做得很好。 不幸的是,我的标题没有遵循我的单元格宽度。 这是我的结果的图片。 如您所见,我的标题与我的单元格不对齐。 这是我的 CSS 代码,就像我说我是
我试图在我的 Material 表上使用 mat-sort 和 mat-paginator,但似乎不起作用。 Table 确实获取了 dataSource.data 中的数据,它也显示在 mat-ta
我试图在我的 Material 表上使用 mat-sort 和 mat-paginator,但似乎不起作用。 Table 确实获取了 dataSource.data 中的数据,它也显示在 mat-ta
我想在每个 mat-option 文本上设置悬停样式,我希望文本显示在 mat-option 之外。为了实现这一点,我应用了非常高的 z-index 值,但没有任何改变。我尝试将 z-index 添加
默认情况下 mat-drawer-container/mat-sidenav-container 和 mat-drawer/mat-sidenav 高度基于 mat-drawer-cont
在 mat-card-header 中提供图像头像通过 mat-card-avatar 得到很好的支持. 在许多用例中,我们希望使用图标而不是图像作为卡片的“头像”。 有没有一种简单的方法可以用图标替
我想要一个包含 2 列的网格列表,并且在这些列中我想要 2 个垂直堆叠的复选框。 我看过 this question 这确实有点 工作,但我想知道是否有更简洁的方法解决这个问题,因为我必须使用大量的
更新:stackbliz https://angular-2wqf4b.stackblitz.io 我正在构建一个比较屏幕,我们可以在其中比较两个项目。我试图将这两项显示为两个 mat-cards里
试图模仿 Material guide 的外观,我无法让工具栏的阴影呈现在 mat-sidenav-container 元素之上: 显示工具栏和 sidenav 的页面,但投影不可见: 单独显示工具栏
请注意,分页/排序无法正常工作。分页不显示它显示的元素数量并且排序不起作用,但是如果您删除 html 文件中的行 *ngIf="dataSource?.filteredData.length > 0"
这个问题在这里已经有了答案: 关闭 10 年前。 Possible Duplicate: Proper stack and heap usage in C++? Heap vs Stack allo
单击每个单选按钮时,我需要为每个垫卡添加背景。背景应仅适用于与单击的垫单选按钮对应的垫卡。
Mat a = (Mat_(3,3) = 2 int dims; //! the number of rows and columns or (-1, -1) when the arr
我是一名优秀的程序员,十分优秀!