我有这个问题,我的应用程序工作正常,但这个错误在IDE中显示。
employee.service.ts:
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class EmployeeService {
getEmployee(){
return [
{"id":1,"name":"Micheal","age":21},
{"id":2,"name":"Jackson","age":22},
{"id":3,"name":"Hales","age":23},
{"id":4,"name":"Moz","age":25}
];
}
constructor() { }
}
我的employeeDetail.ts文件是这样的:
import { Component, OnInit } from '@angular/core';
import { EmployeeService } from '../services/employee.service';
@Component({
selector: 'employee-detail',
templateUrl: './employee-detail.component.html',
styleUrls: ['./employee-detail.component.css']
})
export class EmployeeDetailComponent implements OnInit {
public employees = [];
constructor(private _employeeService : EmployeeService) {
}
ngOnInit() {
this.employees = this._employeeService.getEmployee();
}
}
这是Employee-list.ts
import { Component, OnInit } from '@angular/core';
import {HttpClientModule} from '@angular/common/http';
import { EmployeeService } from '../services/employee.service';
@Component({
selector: 'employee-list',
templateUrl: './employee-list.component.html',
styleUrls: ['./employee-list.component.css']
})
export class EmployeeListComponent implements OnInit {
public employees = []
constructor(private _employeeService : EmployeeService) {
}
ngOnInit() {
this.employees = this._employeeService.getEmployee();
}
}
我该如何解决这个问题?真正的问题是什么?因为我是angular6的新手,所以我找不到这个错误,请解释一下。谢谢。
发布于 2019-11-08 15:26:56
这似乎与新的Angular编译器选项fullTemplateTypeCheck有关,如果该选项在tsconfig文件中设置为true,则会出现错误。
以下是再现构建错误的tsconfig.app.json文件的示例:
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"baseUrl": "./",
"module": "es2015",
"types": []
},
"angularCompilerOptions": {
"fullTemplateTypeCheck": true
},
"exclude": [
"test.ts",
"**/*.spec.ts"
]
}
发布于 2019-10-22 19:35:45
使用Angular8时,我在这一行上有相同的错误触发器:
private configService= new ConfigService();
其中ConfigService按照演示使用HttpClient。
我在我的组件中使用new构造服务,它需要HttpClient作为参数来实例化服务。
@Component({
selector: 'app-main',
templateUrl: './main.component.html',
styleUrls: ['./main.component.css' ],
})
export class MainComponent {
private dataService= new ConfigService();
}
更改为此选项,错误就会消失。注意添加的行提供程序: ConfigService
@Component({
selector: 'app-main',
templateUrl: './main.component.html',
styleUrls: ['./main.component.css' ],
providers: [ConfigService]
})
export class MainComponent {
private dataService: ConfigService;
}
希望这能有所帮助。
发布于 2020-12-29 16:32:59
有时你在一个函数中遗漏了一个参数,在本地构建时它可以很好地工作,但对于生产构建,它将查找该参数并在缺少参数时抛出错误。
https://stackoverflow.com/questions/52191925
复制相似问题