角错误:StaticInjectorError(平台:核心)[e-> t]: [英] Angular Error : StaticInjectorError (Platform: core)[e -> t]:
问题描述
当我使用--prod
构建APK时,出现以下错误
ERROR Error: StaticInjectorError[e -> t]:
StaticInjectorError(Platform: core)[e -> t]:
NullInjectorError: No provider for t!
at e.get (core.js.pre-build-optimizer.js:8894)
at core.js.pre-build-optimizer.js:9139
at e (core.js.pre-build-optimizer.js:9083)
at e.get (core.js.pre-build-optimizer.js:8980)
at core.js.pre-build-optimizer.js:9139
at e (core.js.pre-build-optimizer.js:9083)
at e.get (core.js.pre-build-optimizer.js:8980)
at Ua (core.js.pre-build-optimizer.js:21119)
at e.get (core.js.pre-build-optimizer.js:21808)
at Ts (core.js.pre-build-optimizer.js:22179)
但是与Ionic Cordova一起构建android还是可以的,它也可以与ng serve
一起工作;但是我在ng serve --prod"
上遇到了同样的错误.
我该如何解决?
您正尝试使用未在AppModule提供程序中或component.ts内部列出的服务.将服务添加到提供商列表以使其正常运行.
在app.modules中,如果您希望该服务是全局的(与应用程序上下文有关).
@NgModule({
declarations: [...],
imports: [...],
bootstrap: [...],
entryComponents: [...],
providers: [
MyService
]
})
或者在您的component.ts中,如果您希望该服务与所需的组件相关联.
@Component({
selector: '...',
templateUrl: '...',
providers: [MyService]
})
不要在两个文件中都添加它.同样,当您将服务注入app.modules或component中时,也不要忘记导入该服务.
import { MyService } from '../services/myservice';
这个问题也可以为您提供帮助:错误:没有提供t的提供者 >
As I am build the APK with --prod
I am getting the error below
ERROR Error: StaticInjectorError[e -> t]:
StaticInjectorError(Platform: core)[e -> t]:
NullInjectorError: No provider for t!
at e.get (core.js.pre-build-optimizer.js:8894)
at core.js.pre-build-optimizer.js:9139
at e (core.js.pre-build-optimizer.js:9083)
at e.get (core.js.pre-build-optimizer.js:8980)
at core.js.pre-build-optimizer.js:9139
at e (core.js.pre-build-optimizer.js:9083)
at e.get (core.js.pre-build-optimizer.js:8980)
at Ua (core.js.pre-build-optimizer.js:21119)
at e.get (core.js.pre-build-optimizer.js:21808)
at Ts (core.js.pre-build-optimizer.js:22179)
But it working fine with Ionic Cordova build android also it working with ng serve
; but I am getting the same above error with ng serve --prod"
.
How can I resolve this?
You are trying to use a service that is not listed in providers of your AppModule or inside you component.ts. Add the service to a providers list to make it work.
In app.modules if you want that service to be global (related to app context).
@NgModule({
declarations: [...],
imports: [...],
bootstrap: [...],
entryComponents: [...],
providers: [
MyService
]
})
Or in your component.ts if you want that service to be contextual to desired component.
@Component({
selector: '...',
templateUrl: '...',
providers: [MyService]
})
Do not add it in both files. Also don't forget to import that service when you inject it either in app.modules or component.
import { MyService } from '../services/myservice';
This question also may help you: Error: No provider for t
这篇关于角错误:StaticInjectorError(平台:核心)[e-> t]:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!