angular - 当我更改引导顺序时,为什么我的 Angular 应用程序卡在加载中?
问题描述
我做了我的第一个组件,它工作正常。第二个组件也可以正常工作。但是,当我将这两个组件添加到 app.module.ts 引导程序时,根据顺序,它会永远加载。
索引.html:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>MyFirstApp</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<!--app-my1>loading...</app-my1-->
<app-my2>loading2...</app-my2>
</body>
</html>
app.module.ts:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { My1 } from './my1/my1.component';
import { My2 } from './my2/my2.component';
@NgModule({
declarations: [
My1,
My2
],
imports: [
BrowserModule
],
providers: [],
bootstrap: [My2] // if I use this line, it works
bootstrap: [My2, My1] // if I use this line, it works
bootstrap: [My1, My2] // if I use this line, it stays loading forever, why?
})
export class AppModule { }
此外,如果我在 index.html 上取消注释 app-my1,它会起作用。但是评论这一行是否应该使应用程序卡在加载中?为什么?
解决方案
引导程序应仅包含根组件 (AppComponent)。您可以在应用程序组件中添加两个新组件作为普通标签,它会正常工作。
推荐阅读
- button - SwiftUI 在按钮上触发操作而无需用户单击按钮
- python - 使用 Scrapy Spider 发送请求标头以避免 403 响应状态
- audio - 使用 CNN 和 Librosa 进行语音识别:我可以结合 MFCC 和音频数据吗?
- c++ - 十六进制的 14 位转换 - MCP2515 和 MAX31855
- ruby-on-rails - 将嵌套属性保存在表单中但没有父级?
- python - Python 在回答之前很长时间请求 -> 请求冻结/挂起
- authentication - PyPI 使用令牌使用的这种身份验证模式的名称是什么?
- php - Symfony - 在学说查询构建器中使用 orWhere()
- javascript - 迷失了理解这个回调函数的作用(BFS,树的宽度级别)
- database - 如何在 postgresql 中解决锁定数据库的更新查询?