我正在转换库(ng-app-state)以使用angular cli,现在v6支持库(yay!).
在一些代码中进行脚手架和复制之后,这是我的第一个问题:
我如何/在哪里添加第三方依赖项?
到package.json,或到projects/ng-app-state/package.json?
当我将 MatProgressSpinnerModule 加载到 app.module.ts 中时,我收到带有“stacktrace”的空 NG0203 错误:
tQ https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1
re https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1
fac https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1
hydrate https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1
get https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1
_resolveInjectorDefTypes https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1
_resolveInjectorDefTypes https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1
PM https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1
create https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1
wA https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1
invoke https://localhost:44378/client/polyfills.js:1
onInvoke https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1
invoke https://localhost:44378/client/polyfills.js:1
run https://localhost:44378/client/polyfills.js:1
run https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1
bootstrapModuleFactory https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1
wA https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1
invoke https://localhost:44378/client/polyfills.js:1
run https://localhost:44378/client/polyfills.js:1
F https://localhost:44378/client/polyfills.js:1
invokeTask https://localhost:44378/client/polyfills.js:1
runTask https://localhost:44378/client/polyfills.js:1
L https://localhost:44378/client/polyfills.js:1
promise callback*d https://localhost:44378/client/polyfills.js:1
scheduleTask https://localhost:44378/client/polyfills.js:1
scheduleTask https://localhost:44378/client/polyfills.js:1
scheduleMicroTask https://localhost:44378/client/polyfills.js:1
F https://localhost:44378/client/polyfills.js:1
then https://localhost:44378/client/polyfills.js:1
bootstrapModule https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1
636 https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1
n https://localhost:44378/client/runtime.js:1
<anonymous> https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1
a https://localhost:44378/client/runtime.js:1
<anonymous> https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1
Run Code Online (Sandbox Code Playgroud)
应用程序模块.ts:
import …Run Code Online (Sandbox Code Playgroud) 我正在尝试按照此示例使用webpack5 模块联合来实现 Angular 中的微前端概念Module federation with Angular,但我面临这个错误
我尝试了这个答案中提供的解决方案,必须从注入上下文调用inject(),但它不起作用。
目前我在这两个应用程序中都使用 Angular 版本 11。
正在导入的应用程序的 package.json (子级)
"resolutions": {
"webpack": "5.0.0"
},
"dependencies": {
"@angular/animations": "11.0.0-next.6",
"@angular/cdk": "11.0.0-next.6",
"@angular/common": "11.0.0-next.6",
"@angular/compiler": "11.0.0-next.6",
"@angular/core": "11.0.0-next.6",
"@angular/forms": "11.0.0-next.6",
"@angular/platform-browser": "11.0.0-next.6",
"@angular/platform-browser-dynamic": "11.0.0-next.6",
"@angular/platform-server": "^11.0.0",
"@angular/router": "11.0.0-next.6",
"@angular/service-worker": "11.0.0-next.6",
"@fortawesome/angular-fontawesome": "^0.8.0",
"@fortawesome/fontawesome-svg-core": "^1.2.32",
"@fortawesome/free-solid-svg-icons": "^5.15.1",
"@ngx-translate/core": "^13.0.0",
"@ngx-translate/http-loader": "^6.0.0",
"angular-font-awesome": "^3.1.2",
"bootstrap": "^4.3.1",
"classlist.js": "^1.1.20150312",
"core-js": "^3.1.4",
"file-saver": "^2.0.2",
"font-awesome": "^4.7.0",
"js2xmlparser": "^4.0.0",
"moment": "^2.25.3",
"moment-timezone": "^0.5.28",
"ngx-webstorage-service": "^4.1.0",
"node-sass": …Run Code Online (Sandbox Code Playgroud) angular micro-frontend webpack-5 angular11 webpack-module-federation
升级到 Angular 11 后,我无法再访问ng serve我的 Web 应用程序。
我正在使用 Spring Doc 和最新的 OpenAPI 生成器 gradle-plutin (5.0.0) 生成客户端。
该问题似乎与我的(生成的)REST 客户端有关。打开 https://localhost:4200 会将以下内容写入控制台:
main.ts:12 Error: inject() must be called from an injection context
at injectInjectorOnly (core.js:4901) [angular]
at Module.??inject (core.js:4911) [angular]
at Object.ApiModule_Factory [as factory] (meditation-rest-client.js:2885) [angular]
at R3Injector.hydrate (core.js:11158) [angular]
at R3Injector.get (core.js:10979) [angular]
at :4200/vendor.js:82591:55 [angular]
at Set.forEach (<anonymous>) [angular]
at R3Injector._resolveInjectorDefTypes (core.js:11016) [angular]
at new NgModuleRef$1 (core.js:25046) [angular]
at NgModuleFactory$1.create (core.js:25100) [angular]
at :4200/vendor.js:100468:45 [angular]
at Object.onInvoke (core.js:28301) …Run Code Online (Sandbox Code Playgroud) 我有一个有角度的项目,结构如下:
\n站点1
\n站点2
\n我知道这并不理想,但事实就是如此。
\n除了应用程序的名称之外,这些package.json文件完全相同。
该项目是在 Angular 8 上启动的,并且一直升级得很好,但是从 11 到 12 我遇到了问题:
\nSite1 构建良好并且运行良好。Site2 构建良好,但运行时立即出错
\n\n\n错误:必须从注入上下文\natjectInjectorOnly(核心:4745)\nat模块调用inject()。\xc9\xb5\xc9\xb5inject(核心:4755)\natObject.RouterModule_Factory [作为工厂](路由器:5999) )\nat R3Injector. Hydro (core.js:11438)\nat R3Injector.get (core.js:11257)\nat core.js:11295\nat Set.forEach ()\nat R3Injector._resolveInjectorDefTypes (core.js:11295 )\nat 新 NgModuleRef$1 (core.js:25325)\nat NgModuleFactory$1.create (core.js:25379)
\n
由于 Site1 工作正常,我认为它一定是调用 SharedModule 的原因?
\n我尝试添加"preserveSymlinks": true,到projects.$name.architect.build.options,但这不起作用。我没有使用npm link,因为另一个模块不是库(我知道它应该这样设置,但事实并非如此)。 …
我想知道如何在抽象类中注入具有多个依赖项的服务,该抽象类将由多个类扩展。
以更有效的方式将其传递到所有构造函数中!
我尝试创建静态,但如果该服务从未被另一个服务实例化,则永远不会分配单例实例变量
像这样的:(只是一个例子)
@Injectable({
providedIn: 'root'
})
export class AnimalService {
constructor(private http: HttpClient, private userService: UserService) {}
countTotalInDB(type): number {
return this.http.get(...);
}
getUserAnimals(userId: number) {
return this.userService.getUser(userId).animals;
}
}
abstract class Animal {
constructor() {}
public getTotalInDataBase(type): number {
// How to get a instance of AnimalService ?
return animalService.countTotalInDB(type);
}
}
export class Cat extends Animal {
constructor() {
super();
}
public getTotalInDataBase(): number {
return super.getTotalInDataBase('cat');
}
}
export class Dog extends Animal {
constructor() …Run Code Online (Sandbox Code Playgroud)