本篇內(nèi)容介紹了“Angular怎么構(gòu)建組件”的有關(guān)知識(shí),在實(shí)際案例的操作過程中,不少人都會(huì)遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!
創(chuàng)新互聯(lián)建站堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:成都網(wǎng)站建設(shè)、成都做網(wǎng)站、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的班戈網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!
Angular怎么構(gòu)建組件?本篇文章給大家介紹一下Angular創(chuàng)建項(xiàng)目的方法,Angular創(chuàng)建組件的三種方式。
命名變化,Angular2 以后官方命名為Angular, 2.0 以前的版本稱為AngualrJS。
1.x 的使用方式是引入AngularJS 的js 文件到網(wǎng)頁,2.0 之后就完全不同了,兩者的區(qū)別類似Java 和JavaScript。

1.安裝全局的 Angular CLI 命令行工具
npm install -g @angular/cli
2.創(chuàng)建項(xiàng)目
ng new angular-tour-of-heroes
注意:node 版本需要在12以上,否則會(huì)提示:“'ng' 不是內(nèi)部或外部命令,也不是可運(yùn)行的程序 或批處理文件。”
3.跑項(xiàng)目
cd angular-tour-of-heroes ng serve --open

1.src文件下,新建文件,命名hello-world.component.ts
import { Component } from "@angular/core";
@Component({
selector: 'hello-world組件',
// templateUrl: './app.component.html',
// styleUrls: ["./app.component.scss"]
template: `<h2>{{text}}</h2>`
})
export class HellowordComponent {
constructor() {}
text = "第一個(gè)模板";
}
2.app.component.html中或app.component.ts中新增組件標(biāo)簽

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

使用cli創(chuàng)建組件
輸入命令:
ng generate component hello-world

1.在vscode下載 Angular Files

2.在components下面右鍵,則出現(xiàn)下圖

3.點(diǎn)擊Generater component輸入組件名回車

4.組件生成

“Angular怎么構(gòu)建組件”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!
網(wǎng)站標(biāo)題:Angular怎么構(gòu)建組件
文章分享:http://chinadenli.net/article20/phdsjo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供自適應(yīng)網(wǎng)站、品牌網(wǎng)站設(shè)計(jì)、標(biāo)簽優(yōu)化、網(wǎng)站策劃、關(guān)鍵詞優(yōu)化、移動(dòng)網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)