<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ Angular - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ freeCodeCamp 是一个免费学习编程的开发者社区，涵盖 Python、HTML、CSS、React、Vue、BootStrap、JSON 教程等，还有活跃的技术论坛和丰富的社区活动，在你学习编程和找工作时为你提供建议和帮助。 ]]>
        </description>
        <link>https://www.freecodecamp.org/chinese/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ Angular - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/chinese/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Mon, 18 May 2026 10:23:37 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/chinese/news/tag/angular/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ 如何给一个 Angular 应用添加 Bootstrap ]]>
                </title>
                <description>
                    <![CDATA[ 在这篇文章中，我们将使用最新版本的 Angular 构建一个 web 应用。然后我们将添加 Bootstrap CSS 框架，它提供了丰富的、响应式的界面组件。 让我们开始吧。 前提条件 在你开始之前，你需要安装和配置下面的工具来创建 Angular 应用程序。  * Git [https://git-scm.com/]：Git 是一个分布式版本控制系统，我们将用它来同步仓库。  * Node.js 和 npm [https://nodejs.org/]：Node.js 是一个基于谷歌 V8 引擎的 JavaScript    代码运行时软件。npm 是 Node.js 的一个包管理器（Node Package Manager）。我们将使用这些工具来构建和运行 Angular    应用程序并安装库。  * Angular CLI [https://angular.io/cli]：Angular CLI 是 Angular ]]>
                </description>
                <link>https://www.freecodecamp.org/chinese/news/how-to-add-bootstrap-css-framework-to-an-angular-application/</link>
                <guid isPermaLink="false">6445284474421606ea066184</guid>
                
                    <category>
                        <![CDATA[ Bootstrap ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Angular ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Miya Liu ]]>
                </dc:creator>
                <pubDate>Tue, 18 Apr 2023 02:40:00 +0000</pubDate>
                <media:content url="https://chinese.freecodecamp.org/news/content/images/2023/04/angular-bootstrap-cover-hashnode.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p data-test-label="translation-intro">
        <strong>原文：</strong> <a href="https://www.freecodecamp.org/news/how-to-add-bootstrap-css-framework-to-an-angular-application/" target="_blank" rel="noopener noreferrer" data-test-label="original-article-link">How to Add Bootstrap to an Angular Application</a>
      </p><p>在这篇文章中，我们将使用最新版本的 Angular 构建一个 web 应用。然后我们将添加 Bootstrap CSS 框架，它提供了丰富的、响应式的界面组件。</p><p>让我们开始吧。</p><h2 id="-">前提条件</h2><p>在你开始之前，你需要安装和配置下面的工具来创建 Angular 应用程序。</p><ul><li><a href="https://git-scm.com/">Git</a>：Git 是一个分布式版本控制系统，我们将用它来同步仓库。</li><li><a href="https://nodejs.org/">Node.js 和 npm</a>：Node.js 是一个基于谷歌 V8 引擎的 JavaScript 代码运行时软件。npm 是 Node.js 的一个包管理器（Node Package Manager）。我们将使用这些工具来构建和运行 Angular 应用程序并安装库。</li><li><a href="https://angular.io/cli">Angular CLI</a>：Angular CLI 是 Angular 的一个命令行工具，我们将用它来创建 Angular 应用程序的基础结构。</li><li>集成开发环境（如 <a href="https://code.visualstudio.com/">Visual Studio Code</a> 或 <a href="https://www.jetbrains.com/webstorm/">WebStorm</a>）：集成开发环境是一种具有图形界面的工具，可以帮助你开发应用程序。我们将使用它来开发我们的 Angular 应用程序。</li></ul><h2 id="-angular-">如何创建 Angular 应用程序</h2><p><a href="https://angular.io/">Angular</a> 是一个开发平台，用于使用 HTML、CSS 和 TypeScript（JavaScript）构建 Web、移动和桌面应用程序。目前，Angular 的版本为 13，谷歌是该项目的主要维护者。</p><p><a href="https://getbootstrap.com/">Bootstrap</a> 是一个开源的 CSS 框架，它有许多组件用于构建响应式 web 界面。</p><p>让我们使用 <code>@angular/cli</code> 与路由文件和 SCSS 样式格式创建具有 Angular 基础结构的应用程序。</p><pre><code class="language-powershell">ng new angular-bootstrap
? Would you like to add Angular routing? Yes
? Which stylesheet format would you like to use? SCSS   [ https://sass-lang.com/documentation/syntax#scss                ]
CREATE angular-bootstrap/README.md (1062 bytes)
CREATE angular-bootstrap/.editorconfig (274 bytes)
CREATE angular-bootstrap/.gitignore (604 bytes)
CREATE angular-bootstrap/angular.json (3273 bytes)
CREATE angular-bootstrap/package.json (1079 bytes)
CREATE angular-bootstrap/tsconfig.json (783 bytes)
CREATE angular-bootstrap/.browserslistrc (703 bytes)
CREATE angular-bootstrap/karma.conf.js (1434 bytes)
CREATE angular-bootstrap/tsconfig.app.json (287 bytes)
CREATE angular-bootstrap/tsconfig.spec.json (333 bytes)
CREATE angular-bootstrap/src/favicon.ico (948 bytes)
CREATE angular-bootstrap/src/index.html (302 bytes)
CREATE angular-bootstrap/src/main.ts (372 bytes)
CREATE angular-bootstrap/src/polyfills.ts (2820 bytes)
CREATE angular-bootstrap/src/styles.scss (80 bytes)
CREATE angular-bootstrap/src/test.ts (743 bytes)
CREATE angular-bootstrap/src/assets/.gitkeep (0 bytes)
CREATE angular-bootstrap/src/environments/environment.prod.ts (51 bytes)
CREATE angular-bootstrap/src/environments/environment.ts (658 bytes)
CREATE angular-bootstrap/src/app/app-routing.module.ts (245 bytes)
CREATE angular-bootstrap/src/app/app.module.ts (393 bytes)
CREATE angular-bootstrap/src/app/app.component.scss (0 bytes)
CREATE angular-bootstrap/src/app/app.component.html (23809 bytes)
CREATE angular-bootstrap/src/app/app.component.spec.ts (1090 bytes)
CREATE angular-bootstrap/src/app/app.component.ts (222 bytes)
✔ Packages installed successfully.
    Successfully initialized git.
</code></pre><p>现在我们需要安装 <code>bootstrap</code> 和 <code>bootstrap-icons</code> 库，其中包含具有 Bootstrap 的样式和 JavaScript 代码的文件，像这样：</p><pre><code class="language-powershell">npm install bootstrap bootstrap-icons
</code></pre><p>安装后，我们将配置 <code>bootstrap</code> 和 <code>bootstrap-icons</code> 库。修改 <code>angular.json</code> 文件并添加 <code>bootstrap.scss</code>、<code>bootstrap-icons.css</code> 和 <code>bootstrap.bundle.min.js</code> 文件，如下所示：</p><pre><code class="language-json">"styles": [
  "node_modules/bootstrap/scss/bootstrap.scss",
  "node_modules/bootstrap-icons/font/bootstrap-icons.css",
  "src/styles.scss"
],
"scripts": [
  "node_modules/bootstrap/dist/js/bootstrap.bundle.min.js"
]
</code></pre><p>现在我们将安装 <code>@ng-bootstrap/ng-bootstrap</code> 库，其中包含原生 Angular 支持：</p><pre><code class="language-powershell">npm install @ng-bootstrap/ng-bootstrap@next
</code></pre><p>安装后，我们将导入 <code>NgbModule</code> 模块。改变 <code>app.module.ts</code> 文件并添加以下几行：</p><pre><code class="language-typescript">import { NgbModule } from '@ng-bootstrap/ng-bootstrap';

imports: [
  BrowserModule,
  NgbModule,
  AppRoutingModule,
],
</code></pre><p>现在我们将从 <code>src/app/app.component.ts</code> 文件中删除 <code>AppComponent</code> 类的内容。导入 <code>NgbModal</code> 服务并创建 <code>open</code> 方法以打开一个模态，如下所示：</p><pre><code class="language-typescript">import { Component } from '@angular/core';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss'],
})
export class AppComponent {

  constructor(private modalService: NgbModal) {
  }

  public open(modal: any): void {
    this.modalService.open(modal);
  }

}
</code></pre><p>接下来我们将删除 <code>src/app/app.component.html</code> 文件中的内容。在 HTML 中添加一些组件，以查看和测试这些组件，如下所示：</p><pre><code class="language-html">&lt;nav class="navbar navbar-expand-sm navbar-light bg-light"&gt;
  &lt;div class="container-fluid"&gt;
    &lt;a class="navbar-brand" href="#"&gt;
      &lt;h1&gt;Angular Bootstrap&lt;/h1&gt;
    &lt;/a&gt;
    &lt;button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"&gt;
      &lt;span class="navbar-toggler-icon"&gt;&lt;/span&gt;
    &lt;/button&gt;
    &lt;div class="collapse navbar-collapse" id="navbarSupportedContent"&gt;
      &lt;ul class="navbar-nav me-auto mb-2 mb-lg-0"&gt;
        &lt;li class="nav-item"&gt;
          &lt;a class="nav-link active" aria-current="page" href="#"&gt;Home&lt;/a&gt;
        &lt;/li&gt;
        &lt;li class="nav-item"&gt;
          &lt;a class="nav-link" href="#"&gt;Link&lt;/a&gt;
        &lt;/li&gt;
        &lt;li class="nav-item dropdown"&gt;
          &lt;a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false"&gt;
            Dropdown
          &lt;/a&gt;
          &lt;ul class="dropdown-menu" aria-labelledby="navbarDropdown"&gt;
            &lt;li&gt;&lt;a class="dropdown-item" href="#"&gt;Action&lt;/a&gt;&lt;/li&gt;
            &lt;li&gt;&lt;a class="dropdown-item" href="#"&gt;Another action&lt;/a&gt;&lt;/li&gt;
            &lt;li&gt;&lt;hr class="dropdown-divider"&gt;&lt;/li&gt;
            &lt;li&gt;&lt;a class="dropdown-item" href="#"&gt;Something else here&lt;/a&gt;&lt;/li&gt;
          &lt;/ul&gt;
        &lt;/li&gt;
        &lt;li class="nav-item"&gt;
          &lt;a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true"&gt;Disabled&lt;/a&gt;
        &lt;/li&gt;
      &lt;/ul&gt;
      &lt;form class="d-flex"&gt;
        &lt;input class="form-control me-2" type="search" placeholder="Search" aria-label="Search"&gt;
        &lt;button class="btn btn-outline-success" type="submit"&gt;Search&lt;/button&gt;
      &lt;/form&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/nav&gt;
&lt;div class="container-fluid py-3"&gt;
  &lt;div class="row my-3"&gt;
    &lt;div class="col"&gt;
      &lt;label for="exampleFormControlInput1" class="form-label"&gt;Email address&lt;/label&gt;
      &lt;input type="email" class="form-control form-control-sm" id="exampleFormControlInput1" placeholder="name@example.com"&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="row my-3"&gt;
    &lt;div class="col"&gt;
      &lt;label for="exampleFormControlTextarea1" class="form-label"&gt;Example textarea&lt;/label&gt;
      &lt;textarea class="form-control form-control-sm" id="exampleFormControlTextarea1" rows="3"&gt;&lt;/textarea&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="row my-3"&gt;
    &lt;div class="col"&gt;
      &lt;div class="form-check form-switch"&gt;
        &lt;input class="form-check-input" type="checkbox" id="flexSwitchCheckDefault"&gt;
        &lt;label class="form-check-label" for="flexSwitchCheckDefault"&gt;Default switch checkbox input&lt;/label&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="row my-3"&gt;
    &lt;div class="col"&gt;
      &lt;button class="btn btn-sm btn-outline-primary" (click)="open(demoModal)"&gt;Launch demo modal&lt;/button&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;ng-template #demoModal let-modal&gt;
  &lt;div class="modal-header"&gt;
    &lt;h4 class="modal-title" id="modal-basic-title"&gt;Profile update&lt;/h4&gt;
    &lt;button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close" (click)="modal.dismiss('Cross click')"&gt;&lt;/button&gt;
  &lt;/div&gt;
  &lt;div class="modal-body"&gt;
    &lt;form&gt;
      &lt;div class="form-group"&gt;
        &lt;label for="dateOfBirth"&gt;Date of birth&lt;/label&gt;
        &lt;div class="input-group"&gt;
          &lt;input id="dateOfBirth" name="dateOfBirth" class="form-control" placeholder="yyyy-mm-dd" ngbDatepicker #dp="ngbDatepicker"&gt;
          &lt;button type="button" class="btn btn-outline-secondary bi bi-calendar" (click)="dp.toggle()"&gt;&lt;/button&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/form&gt;
  &lt;/div&gt;
  &lt;div class="modal-footer"&gt;
    &lt;button type="button" class="btn btn-outline-dark" (click)="modal.close('Save click')"&gt;Save&lt;/button&gt;
  &lt;/div&gt;
&lt;/ng-template&gt;
</code></pre><p>最后，我们将用下面的命令运行该应用程序：</p><pre><code class="language-powershell">npm start

&gt; angular-bootstrap@1.0.0 start
&gt; ng serve

✔ Browser application bundle generation complete.

Initial Chunk Files | Names         |      Size
vendor.js           | vendor        |   3.38 MB
styles.css          | styles        | 255.86 kB
polyfills.js        | polyfills     | 128.56 kB
scripts.js          | scripts       |  76.94 kB
main.js             | main          |  22.81 kB
runtime.js          | runtime       |   6.59 kB

                    | Initial Total |   3.86 MB

Build at: 2021-06-27T21:28:22.756Z - Hash: 122b9fa4d57b962e7bcc - Time: 21933ms

** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **


✔ Compiled successfully.
</code></pre><p>准备好了！我们将访问 <code>http://localhost:4200/</code>，并检查应用程序是否在工作。你可以在 <a href="https://rodrigokamada.github.io/angular-bootstrap/">GitHub Pages</a> 和 <a href="https://stackblitz.com/edit/angular13-bootstrap">Stackblitz</a> 上看到该应用程序正在工作。</p><figure class="kg-card kg-image-card"><img src="https://www.freecodecamp.org/news/content/images/2022/04/angular-bootstrap.png" class="kg-image" alt="angular-bootstrap" width="600" height="400" loading="lazy"></figure><p>应用程序的仓库是 <a href="https://github.com/rodrigokamada/angular-bootstrap">https://github.com/rodrigokamada/angular-bootstrap</a>。</p><h2 id="--1">总结</h2><p>让我们总结一下本文的内容：</p><ul><li>我们创建了一个 Angular 应用程序。</li><li>我们添加了一些 Bootstrap CSS 框架组件。</li></ul><p>你可以使用这篇文章来创建丰富的、响应式的应用程序，提供更好的用户体验和更大的可用性。</p><p>感谢阅读，希望你喜欢这篇文章！</p><p>这篇教程是在我的<a href="https://rodrigo.kamada.com.br/share/blog/adicionando-o-framework-de-css-bootstrap-em-uma-aplicacao-angular">博客</a>上用葡萄牙语发布的。</p><p>请在 <a href="https://twitter.com/rodrigokamada">Twitter</a> 上关注我，以便及时阅读我更新的文章。</p> ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ 如何用 Travis CI 在 GitHub 页面上托管一个 Angular 应用程序 ]]>
                </title>
                <description>
                    <![CDATA[ 原文：How to Host an Angular Application on GitHub Pages with Travis CI [https://www.freecodecamp.org/news/host-an-angular-application-on-github-pages-with-travis-ci/] ，作者：Rodrigo Kamada [https://www.freecodecamp.org/news/author/rodrigokamada/] 在本文中，我们将使用最新版本的 Angular 创建一个应用程序。然后我们将它托管在 GitHub 页面的静态网站服务上，使用持续集成工具 Travis CI 来部署该应用程序。 前提 在开始之前，你需要安装和配置以下工具来创建 Angular 应用程序。  * Git [https://git-scm.com/]：Git 是一个分布式版本控制系统，我们将使用它来同步仓库。  * Node.js and npm [https://nodejs.org/]：Node.js 是一个基于谷歌 V8 引擎的 Ja ]]>
                </description>
                <link>https://www.freecodecamp.org/chinese/news/host-an-angular-application-on-github-pages-with-travis-ci/</link>
                <guid isPermaLink="false">627a2894c9c067061df8b817</guid>
                
                    <category>
                        <![CDATA[ Angular ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Jing Wu ]]>
                </dc:creator>
                <pubDate>Tue, 10 May 2022 07:00:00 +0000</pubDate>
                <media:content url="https://chinese.freecodecamp.org/news/content/images/2022/05/angular-travisci-cover-1.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>原文：<a href="https://www.freecodecamp.org/news/host-an-angular-application-on-github-pages-with-travis-ci/">How to Host an Angular Application on GitHub Pages with Travis CI</a>，作者：<a href="https://www.freecodecamp.org/news/author/rodrigokamada/">Rodrigo Kamada</a></p><!--kg-card-begin: markdown--><p>在本文中，我们将使用最新版本的 Angular 创建一个应用程序。然后我们将它托管在 GitHub 页面的静态网站服务上，使用持续集成工具 Travis CI 来部署该应用程序。</p>
<h2 id="">前提</h2>
<p>在开始之前，你需要安装和配置以下工具来创建 Angular 应用程序。</p>
<ul>
<li><a href="https://git-scm.com/">Git</a>：Git 是一个分布式版本控制系统，我们将使用它来同步仓库。</li>
<li><a href="https://nodejs.org/">Node.js and npm</a>：Node.js 是一个基于谷歌 V8 引擎的 JavaScript 代码运行时软件。 npm 是 Node.js 的包管理器（Node Package Manager）。我们将使用这些来构建和运行 Angular 应用程序并安装库（依赖库）。</li>
<li><a href="https://angular.io/cli">Angular CLI</a>：Angular CLI 是 Angular 的一个命令行实用工具，我们将使用它来创建 Angular 应用程序的基本结构。</li>
<li>IDE（例如 <a href="https://code.visualstudio.com/">Visual Studio Code</a> 或 <a href="https://www.jetbrains.com/webstorm/">WebStorm</a>）：IDE（集成开发环境）是具有图形界面的工具，可帮助我们开发应用程序。在这里，我们将使用其中一个来开发 Angular 应用程序。</li>
</ul>
<h2 id="">开始</h2>
<h3 id="github">在 GitHub 上创建和配置你的帐户</h3>
<p><a href="https://github.com/">GitHub</a> 是一个使用 Git 工具进行版本控制的源代码和文件存储服务。<a href="https://pages.github.com/">GitHub Pages</a> 是使用公共仓库的静态文件托管服务。</p>
<p>首先，如果你还没有帐户，则需要在 GitHub 上创建一个帐户。访问 <a href="https://github.com/">https://github.com/</a> 并点击按钮 <em>Sign up</em>。</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/github-step1.png" alt="github-step1" width="600" height="400" loading="lazy"></p>
<p>填写用户名、电子邮件地址和密码字段，点击 “Verify” 按钮通过测试，然后点击 “Create account” 按钮。</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/github-step2.png" alt="github-step2" width="600" height="400" loading="lazy"></p>
<p>接下来，我们会生成在 Travis CI 中使用到的令牌。单击你的头像打开菜单，然后单击菜单 Settings。</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/github-step3.png" alt="github-step3" width="600" height="400" loading="lazy"></p>
<p>单击菜单 Developer settings。</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/github-step4.png" alt="github-step4" width="600" height="400" loading="lazy"></p>
<p>单击菜单 Personal access tokens。</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/github-step5.png" alt="github-step5" width="600" height="400" loading="lazy"></p>
<p>点击按钮 Generate new token。</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/github-step6.png" alt="github-step6" width="600" height="400" loading="lazy"></p>
<p>填写字段 Note，选择选项 repo 并点击按钮 Create token。</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/github-step7.png" alt="github-step7" width="600" height="400" loading="lazy"></p>
<p>复制生成的令牌。因为接下来该令牌将在 Travis CI 中配置。在我的例子中，“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” 就是我生成的令牌。</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/github-step8.png" alt="github-step8" width="600" height="400" loading="lazy"></p>
<p>让我们创建仓库。单击你的头像打开菜单，然后单击菜单 Your repositories。</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/github-step9.png" alt="github-step9" width="600" height="400" loading="lazy"></p>
<p>点击按钮 New。</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/github-step10.png" alt="github-step10" width="600" height="400" loading="lazy"></p>
<p>填写仓库名称字段并单击按钮 Create repository。</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/github-step11.png" alt="github-step11" width="600" height="400" loading="lazy"></p>
<p>准备好了！帐户已创建好、令牌已生成，并且仓库 <a href="https://github.com/rodrigokamada/angular-travisci"><code>https://github.com/rodrigokamada/angular-travisci</code></a> 也创建好了。</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/github-step12.png" alt="github-step12" width="600" height="400" loading="lazy"></p>
<h3 id="travisci">在 Travis CI 上创建和配置你的帐户</h3>
<p><a href="https://www.travis-ci.com/">Travis CI</a> 是与 GitHub 集成的部署服务。</p>
<p>首先，如果你还没有 Travis CI 帐户，则需要创建一个。访问 <a href="https://travis-ci.com/">https://travis-ci.com/</a> 并点击按钮 Sign up。</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/travisci-step1.png" alt="travisci-step1" width="600" height="400" loading="lazy"></p>
<p>单击 SIGN IN WITH GITHUB 按钮以使用你的 GitHub 帐户登录。</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/travisci-step2.png" alt="travisci-step2" width="600" height="400" loading="lazy"></p>
<p>如果 Travis CI 请求列出 GitHub 仓库的权限，则接受该请求。单击仓库链接 angular-travisci。</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/travisci-step3.png" alt="travisci-step3" width="600" height="400" loading="lazy"></p>
<p>让我们设置 GitHub 访问令牌。单击菜单 More options，然后单击菜单 Settings。</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/travisci-step4.png" alt="travisci-step4" width="600" height="400" loading="lazy"></p>
<p>字段 NAME的值填写为 GITHUB_TOKEN ，VALUE 的值填写为你在 GitHub 上生成的令牌的值，然后单击按钮 Add。</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/travisci-step5.png" alt="travisci-step5" width="600" height="400" loading="lazy"></p>
<p>准备好了！账户已创建，仓库也已配置好了。</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/travisci-step6.png" alt="travisci-step6" width="600" height="400" loading="lazy"></p>
<h3 id="angular">创建你的 Angular 应用程序</h3>
<p><a href="https://angular.io/">Angular</a> 是一个使用 HTML、CSS 和 TypeScript（JavaScript）构建 Web、移动和桌面应用程序的开发平台。目前，Angular 的版本为 13，Google 是该项目的主要维护者。</p>
<p>让我们使用带有路由文件和 SCSS 样式格式的 <code>@angular/cli</code> 创建具有 Angular 基础结构的应用程序。</p>
<pre><code class="language-powershell">? Would you like to add Angular routing? Yes
? Which stylesheet format would you like to use? SCSS   [ https://sass-lang.com/documentation/syntax#scss                ]
CREATE angular-travisci/README.md (1061 bytes)
CREATE angular-travisci/.editorconfig (274 bytes)
CREATE angular-travisci/.gitignore (604 bytes)
CREATE angular-travisci/angular.json (3267 bytes)
CREATE angular-travisci/package.json (1078 bytes)
CREATE angular-travisci/tsconfig.json (783 bytes)
CREATE angular-travisci/.browserslistrc (703 bytes)
CREATE angular-travisci/karma.conf.js (1433 bytes)
CREATE angular-travisci/tsconfig.app.json (287 bytes)
CREATE angular-travisci/tsconfig.spec.json (333 bytes)
CREATE angular-travisci/src/favicon.ico (948 bytes)
CREATE angular-travisci/src/index.html (301 bytes)
CREATE angular-travisci/src/main.ts (372 bytes)
CREATE angular-travisci/src/polyfills.ts (2820 bytes)
CREATE angular-travisci/src/styles.scss (80 bytes)
CREATE angular-travisci/src/test.ts (743 bytes)
CREATE angular-travisci/src/assets/.gitkeep (0 bytes)
CREATE angular-travisci/src/environments/environment.prod.ts (51 bytes)
CREATE angular-travisci/src/environments/environment.ts (658 bytes)
CREATE angular-travisci/src/app/app-routing.module.ts (245 bytes)
CREATE angular-travisci/src/app/app.module.ts (393 bytes)
CREATE angular-travisci/src/app/app.component.scss (0 bytes)
CREATE angular-travisci/src/app/app.component.html (23809 bytes)
CREATE angular-travisci/src/app/app.component.spec.ts (1087 bytes)
CREATE angular-travisci/src/app/app.component.ts (221 bytes)
✔ Packages installed successfully.
    Successfully initialized git.
</code></pre>
<p>创建 <code>.travis.yml</code> 文件。</p>
<pre><code class="language-powershell">touch .travis.yml
</code></pre>
<p>使用以下内容配置  <code>.travis.yml</code> 文件。</p>
<pre><code class="language-yaml">notifications:
  email:
    recipients:
      - rodrigo@kamada.com.br

language: node_js

node_js:
  - 16

before_script:
  - npm install

script:
  - npm run test:headless

before_deploy:
  - npm run build:prod

deploy:
  provider: pages
  skip_cleanup: true
  github_token: $GITHUB_TOKEN
  local_dir: dist/angular-travisci
  on:
    branch: main
</code></pre>
<p>更改 <code>package.json</code> 文件，并添加以下脚本。 将 <code>rodrigokamada</code> 替换为你的 GitHub 用户名。</p>
<pre><code class="language-json">  "build:prod": "ng build --prod --base-href https://rodrigokamada.github.io/angular-travisci/",
  "test:headless": "ng test --watch=false --browsers=ChromeHeadless"
</code></pre>
<p>更改 <code>src/app/app.component.spec.ts</code> 文件并删除测试 <code>should have as title 'angular-travisci'</code> 和 <code>should render title</code>。</p>
<p>使用以下命令运行测试：</p>
<pre><code class="language-powershell">npm run test:headless

&gt; angular-travisci@1.0.0 test:headless
&gt; ng test --watch=false --browsers=ChromeHeadless

⠋ Generating browser application bundles (phase: setup)...Compiling @angular/core/testing : es2015 as esm2015
Compiling @angular/compiler/testing : es2015 as esm2015
Compiling @angular/platform-browser/testing : es2015 as esm2015
Compiling @angular/common/testing : es2015 as esm2015
Compiling @angular/platform-browser-dynamic/testing : es2015 as esm2015
Compiling @angular/router/testing : es2015 as esm2015
⠸ Generating browser application bundles (phase: building)...05 09 2021 19:40:04.329:INFO [karma-server]: Karma v6.3.4 server started at http://localhost:9876/
05 09 2021 19:40:04.331:INFO [launcher]: Launching browsers ChromeHeadless with concurrency unlimited
05 09 2021 19:40:04.369:INFO [launcher]: Starting browser ChromeHeadless
✔ Browser application bundle generation complete.
05 09 2021 19:40:09.704:INFO [Chrome Headless 92.0.4515.159 (Linux x86_64)]: Connected on socket NUtJhjavb1JvssqOAAAB with id 25989029
Chrome Headless 92.0.4515.159 (Linux x86_64): Executed 1 of 1 SUCCESS (0.068 secs / 0.042 secs)
TOTAL: 1 SUCCESS
</code></pre>
<p>使用以下命令运行应用程序，访问地址  <code>http://localhost:4200/</code>，并检查该应用程序是否正常工作。</p>
<pre><code class="language-powershell">npm start

&gt; angular-travisci@1.0.0 start
&gt; ng serve

✔ Browser application bundle generation complete.

Initial Chunk Files | Names         |      Size
vendor.js           | vendor        |   2.39 MB
polyfills.js        | polyfills     | 128.51 kB
main.js             | main          |   8.89 kB
runtime.js          | runtime       |   6.63 kB
styles.css          | styles        |   1.18 kB

                    | Initial Total |   2.53 MB

Build at: 2021-09-05T22:35:38.010Z - Hash: a4cfc9149589386eca5b - Time: 39997ms

** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **


✔ Compiled successfully.
</code></pre>
<p>使用以下命令构建应用程序：</p>
<pre><code class="language-powershell">npm run build:prod

&gt; angular-travisci@1.0.0 build:prod
&gt; ng build --configuration production --base-href https://rodrigokamada.github.io/angular-travisci/

✔ Browser application bundle generation complete.
✔ Copying assets complete.
✔ Index html generation complete.

Initial Chunk Files           | Names         |      Size
main.c678fa8750e7c769.js      | main          | 177.63 kB
polyfills.6d7801353e02e327.js | polyfills     |  36.21 kB
runtime.b136bda8a38c4f2e.js   | runtime       |   1.06 kB
styles.ef46db3751d8e999.css   | styles        |   0 bytes

                              | Initial Total | 214.90 kB

Build at: 2021-09-05T22:42:19.525Z - Hash: 83bfffc079b083727ca4 - Time: 26030ms
</code></pre>
<p>在你创建的 GitHub 仓库上同步应用程序。</p>
<p>准备好了！在 GitHub 仓库上同步应用程序后，Travis CI 会构建应用程序并在分支 <code>gh-pages</code> 上同步。</p>
<p>访问地址 <a href="https://rodrigokamada.github.io/angular-travisci/"><code>https://rodrigokamada.github.io/angular-travisci/</code></a> 并检查应用程序是否正常工作。将 <code>rodrigokamada</code> 值替换为你的 GitHub 用户名。</p>
<p>就是这样！<a href="https://github.com/rodrigokamada/angular-travisci">https://github.com/rodrigokamada/angular-travisci</a> 上的应用程序仓库现在可以用了。</p>
<h2 id="">结语</h2>
<p>总结本文所涵盖的内容：</p>
<ul>
<li>在 GitHub 上创建了一个帐户</li>
<li>在 GitHub 上创建了一个访问令牌</li>
<li>在 GitHub 上创建了一个仓库</li>
<li>在 Travis CI 上创建了一个帐户</li>
<li>在 Travis CI 上配置了 GitHub 访问令牌</li>
<li>创建一个 Angular 应用程序</li>
</ul>
<p>你可以使用本文创建你的个人网站并拥有在线作品集。</p>
<p>感谢你阅读本文，希望你喜欢这篇文章！</p>
<p>如果你需要在我发布新文章时获得最新内容，请在 <a href="https://twitter.com/rodrigokamada">Twitter</a> 上关注我。</p>
<p>本教程以葡萄牙语发布在我的<a href="https://rodrigo.kamada.com.br/share/blog/hospedando-uma-aplicacao-angular-no-github-pages-usando-o-travis-ci">博客</a>。</p>
<!--kg-card-end: markdown--> ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
