站長資訊網
        最全最豐富的資訊網站

        Angular怎么構建組件?3種方法介紹

        Angular怎么構建組件?本篇文章給大家介紹一下Angular創建項目的方法,Angular創建組件的三種方式。

        Angular怎么構建組件?3種方法介紹

        一、angular 與angularjs的區別是什么?

        • 命名變化,Angular2 以后官方命名為Angular, 2.0 以前的版本稱為AngualrJS。【相關教程推薦:《angular教程》】

        • 1.x 的使用方式是引入AngularJS 的js 文件到網頁,2.0 之后就完全不同了,兩者的區別類似Java 和JavaScript。

        Angular怎么構建組件?3種方法介紹

        二、創建一個項目

        1.安裝全局的 Angular CLI 命令行工具

        npm install -g @angular/cli

        2.創建項目

        ng new angular-tour-of-heroes

        注意:node 版本需要在12以上,否則會提示:“'ng' 不是內部或外部命令,也不是可運行的程序 或批處理文件。”

        3.跑項目

        cd angular-tour-of-heroes ng serve --open

        Angular怎么構建組件?3種方法介紹

        三、創建組件的第一種方式:

        1.src文件下,新建文件,命名hello-world.component.ts

        import { Component } from "@angular/core";  @Component({     selector: 'hello-world組件',     // templateUrl: './app.component.html',     // styleUrls: ["./app.component.scss"]     template: `<h1>{{text}}</h1>`  }) export class HellowordComponent {     constructor() {}     text = "第一個模板"; }

        Angular怎么構建組件?3種方法介紹

        2.app.component.html中或app.component.ts中新增組件標簽

        Angular怎么構建組件?3種方法介紹

        // 引入ng核心包和組件 import { Component } from '@angular/core'; @Component({   selector: 'app-root',//當前組件的引用名稱   template:     `   <hello-world></hello-world>//x新增組件標簽      `  ,   // templateUrl: './app.component.html',//組件模板   styles: ['h1 { color:red}']   // styleUrls: ['./app.component.scss']//組件的樣式文件  }) export class AppComponent {//組件名稱  }

        3.app.module.ts中引入組件,聲明組件

        Angular怎么構建組件?3種方法介紹

        四、創建組件的第二種方式:

        使用cli創建組件

        輸入命令:

        ng generate component hello-world

        Angular怎么構建組件?3種方法介紹

        五、創建組件的第三種方式:

        1.在vscode下載 Angular Files

        Angular怎么構建組件?3種方法介紹

        2.在components下面右鍵,則出現下圖

        Angular怎么構建組件?3種方法介紹

        3.點擊Generater component輸入組件名回車

        Angular怎么構建組件?3種方法介紹

        4.組件生成

        Angular怎么構建組件?3種方法介紹

        贊(0)
        分享到: 更多 (0)
        網站地圖   滬ICP備18035694號-2    滬公網安備31011702889846號
        主站蜘蛛池模板: 99精品国产在热久久无毒不卡| 99精品免费视品| 97久久精品无码一区二区天美| 国精品产露脸自拍| 国产精品亚洲а∨无码播放| 欧美精品高清在线xxxx| 在线精品国产一区二区| 国产99视频精品免视看7| 在线观看91精品国产网站| 精品乱码久久久久久夜夜嗨| 国产一精品一av一免费爽爽| 久久99国产乱子伦精品免费| 在线涩涩免费观看国产精品| 麻豆精品视频在线观看91| 99热都是精品久久久久久| 国产精品亚洲一区二区三区在线 | 青草国产精品视频。| 国产精品九九久久免费视频 | 亚洲国产精品久久久久| 国产精品高清一区二区三区 | 国产精品多p对白交换绿帽| 亚洲Av无码精品色午夜| 亚洲精品无码专区久久同性男| 国产亚洲精品资在线| 国产精品成人久久久久久久 | laowang在线精品视频| 国产精品一区二区久久国产| 久久久无码精品亚洲日韩按摩| 四虎成人精品无码| 婷婷国产成人精品视频| 色欲精品国产一区二区三区AV| 在线观看亚洲精品福利片| 亚洲精品蜜桃久久久久久| 中文精品无码中文字幕无码专区| 亚洲av无码成人精品区在线播放| 亚洲国产一成久久精品国产成人综合| 欧美精品亚洲精品日韩专区| 欧美在线精品永久免费播放| 亚洲欧美日韩国产成人精品影院 | 91po国产在线精品免费观看| 国产精品成人观看视频网站|