angular6学习(五):创建组键

两种创建方式:手动创建和命令创建

手动创建:

一:基础知识:

代码说明:

二:代码实现:

   1.在app目录中新建组键目录和文件

    2.ts文件中添加修饰器和引入模板

    

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

  2.  
  3. @Component({

  4. selector: 'app-server',

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

  6. })

  7. export class ServerComponent {

  8.  
  9. }

  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>

  11.  

  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

猜你喜欢

转载自blog.csdn.net/plpldog/article/details/82887973