1. 程式人生 > >angular6學習(五):建立組鍵

angular6學習(五):建立組鍵

兩種建立方式:手動建立和命令建立

手動建立:

一:基礎知識:

程式碼說明:

二:程式碼實現:

   1.在app目錄中新建組鍵目錄和檔案

    2.ts檔案中新增修飾器和引入模板

  1. import {Component} from '@angular/core';

  2. @Component({

  3. selector: 'app-server',

  4. templateUrl: './server.component.html'

  5. })

  6. export class ServerComponent {

  7. }

  3. html檔案中新增內容

  1. <!DOCTYPE html>

  2. <html lang="en">

  3. <head>

  4. <meta charset="UTF-8">

  5. <title>Title</title>

  6. </head>

  7. <body>

  8. <p>這是一個server主鍵</p>

  9. </body>

  10. </html>

  4. 在檔案app.modul.ts中新增server組鍵

  5. 在檔案app.componert.html中引用server組鍵

顯示如下:

命令建立:

一:Alt+F12 開啟命令模式,輸入  ng generate component servers

     或者縮寫 ng g c servers

      指定建立組鍵servers

       自動建立組建目錄和檔案,並自動在modul中新增

二: 在檔案app.componert.html中引用servers組鍵即可

--------------------- 本文來自 七刀 的CSDN 部落格 ,全文地址請點選:https://blog.csdn.net/u011321546/article/details/80739636?utm_source=copy