- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 MAT_DIALOG_DATA 将数据传递到我的对话框,但是,我在我的浏览器控制台中收到此错误。
Uncaught Error: inject() must be called from an injection context
at injectInjectorOnly (core.js:1767)
at inject (core.js:1778)
...
...
...
首先,我必须指出我使用的是 angular 7。
我观看了很多视频并阅读了很多文章,这些文章表明我在我的项目中包含的内容就足够了:- 我从 Angular Material 中导入了 MAT_DIALOG_DATA。- 我使用了对话框引用。- 我在构造函数中定义我的注入(inject)。
这里是 component.ts 代码:
import { Component, OnInit, inject } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA} from '@angular/material';
@Component({
selector: 'app-table-editor-dialog',
templateUrl: './table-editor-dialog.component.html',
styleUrls: ['./table-editor-dialog.component.scss']
})
export class TableEditorDialogComponent implements OnInit {
constructor(
@inject(MAT_DIALOG_DATA) public data: any,
public matDialogRef: MatDialogRef<TableEditorDialogComponent>
) { }
ngOnInit() {
}
getMessageId(id : Number){
}
}
我希望将数据传递给对话框。现在是怎么回事。我的程序编译成功,但在浏览器中,程序停止工作并显示错误中的错误。
Uncaught Error: inject() must be called from an injection context
at injectInjectorOnly (core.js:1767)
最佳答案
导入应该是Inject
,而不是inject
。因此,使用以下导入
import { Component, OnInit, Inject } from '@angular/core';
并且,在组件的构造函数中
constructor(public dialogRef: MatDialogRef<TableEditorDialogComponent>,
@Inject(MAT_DIALOG_DATA) public data: any) { }
关于angular - 我无法注入(inject) MAT_DIALOG_DATA!错误 : inject() must be called from an injection context,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55329999/
我创建了一个名为 customer-edit.component.ts 的组件。有一个页面可以访问客户编辑页面。然而,在其他屏幕上,我希望编辑客户但没有路由到客户页面。所以我通过使用垫对话框来使用弹出
在文档中,他们使用 MAT_DIALOG_DATA 与组件共享数据。 但是,为什么不去 ref.componentInstance.myInput = my_value将数据传递给组件与设置组件实例输
我正在尝试对该 Material 对话框进行单元测试,以测试模板是否渲染正确的注入(inject)对象。如果使用得当,该组件可以正常工作 组件 - 对话框 export class Confirmat
我正在尝试使用 TestBed 为 Angular 组件编写集成测试。使用 @inject(MAT_DIALOG_DATA) 将一些数据注入(inject)到 Material 对话框的组件中.我想测
我正在使用 MAT_DIALOG_DATA 将数据传递到我的对话框,但是,我在我的浏览器控制台中收到此错误。 Uncaught Error: inject() must be called from
我正在使用 MAT_DIALOG_DATA 将数据传递到我的对话框,但是,我在我的浏览器控制台中收到此错误。 Uncaught Error: inject() must be called from
我是一名优秀的程序员,十分优秀!