Angular笔记02--项目启动

启动的相关文件

上次的笔记中我们学习了angular.json是angular cli的配置文件,main.ts是angular项目主入口,现在看看具体是如何一步步启动一个项目的。

首先打开angular.json文件(不知道的可以参考上篇博客
在这里插入图片描述
我们找到"sourceRoot": "src",这行代码表示angular应用启动时从哪个目录找资源,默认指向src目录
我们再看"index": "src/index.html",这行代码表示Angular应用启动时加载的页面 默认指向src目录中index.html
继续看"main": "src/main.ts",这行代码表示Angular应用启动时加载的脚本 默认指向src目录中的main.ts

在main.ts文件中有以下代码,表示程序启动时会去加载AppModule

const bootstrap = () => {
  return platformBrowserDynamic()
    .bootstrapModule(AppModule, {
      defaultEncapsulation: ViewEncapsulation.Emulated,
    })
    .then(res => {
      if ((window as any).appBootstrap) {
        (window as any).appBootstrap();
      }
      return res;
    });
};

在index.html中<app-root></app-root> 这个标签就是组件展示的地方

<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <title>Test</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-root>Loading...</app-root>
</body>
</html>

Angular的完整启动过程

1.首先Angular应用在启动时会去angular.json中寻找要加载的页面和脚本。
默认加载的时index.html与main.ts,启动时在src目录中寻找资源在这里插入图片描述
2.在main.ts中寻找主模块
在这里插入图片描述
3.在app.module中找到指定的主组件,默认的主组件是app.component
在这里插入图片描述
4.最后就是将组件渲染到index.html
在这里插入图片描述


以上是我学习过程中的记录,如有不对的地方还望网友指出。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值