近期做項目,正好用到了AngularJS,所以就想著趕快整理成博文,避免回頭給忘了.第一次接觸AngularJS是兩年前,那會兒公司用的是BootStrap做頁面,然后配合AngularJS1.x做一些處理.后來身邊人極力推薦讓用2.x.說是2.x比1.x有了非常大的變動,但一直沒空去整,一直擱到現(xiàn)在.
AngularJS6.x仍然是基于nodeJS的,所以如果我們想要搭建一個AngularJS的環(huán)境,首先我們要安裝nodeJs,這里要強調(diào)一點,如果我們要用angularJs6.x那么我們安裝的Nodejs版本必須大于等于8.x,并且npm版本必須大于等于5.x.
這里我的操作系統(tǒng)是CentOS7-1804的,然后安裝命令如下:
<pre style="margin-left:66.0pt;text-indent:-18.0pt;mso-list:l3 level1 lfo2">1. 靜默添加nodejs地址 并將他安裝到bash里:
curl --silent --location https://rpm.nodesource.com/setup_10.x | sudo bash -</pre>
<pre style="margin-left:66.0pt;text-indent:-18.0pt;mso-list:l3 level1 lfo2">2. 安裝nodejs的編譯環(huán)境: yum
install gcc-c++
make</pre>
<pre style="margin-left:66.0pt;text-indent:-18.0pt;mso-list:l3 level1 lfo2">3.
安裝nodejs: yum -y
install nodejs
</pre>
<pre style="margin-left:39.75pt;
mso-para-margin-left:1.5gd;text-indent:-24.0pt;mso-char-indent-count:-2.0">安裝之后,運行npm -v效果圖如下:
<pre style="margin-left:
39.75pt;mso-para-margin-left:1.5gd;text-indent:-24.0pt;mso-char-indent-count:
-2.0">運行node -v效果圖如下:
<pre style="text-indent:
18.0pt;mso-char-indent-count:1.5">有了這兩個提示,就說明我們的Nodejs已經(jīng)安裝成功了,然后我們開始安裝AngularJs/cli: sudo npm install -g @angular/cli</pre>
<pre style="text-indent:18.0pt;mso-char-indent-count:1.5">在這里可能會有一些安裝錯誤,此時我們可以卸載然后重新安裝,卸載命令如下:</pre>
<pre style="margin-left:36.0pt;text-indent:-18.0pt;
mso-list:l1 level1 lfo1">1. npm uninstall -g angular-cli卸載舊版本 npm uninstall @angular/cli 卸載新版本</pre>
<pre style="margin-left:36.0pt;text-indent:-18.0pt;mso-list:l1 level1 lfo1">2. npm cache clean 清理緩存 npm cache verify –force 強制清理緩存 </pre>
<pre style="text-indent:18.0pt;
mso-char-indent-count:1.5">另外,我們安裝執(zhí)行過后,可能會出現(xiàn)如下圖一樣的警告,這是因為fsevents@1.2.4是mac系統(tǒng)使用的,如果我們使用的是其他的系統(tǒng)就會出現(xiàn)這樣的提醒,所以這樣是正常的:
<pre style="text-indent:18.0pt;mso-char-indent-count:1.5">截止到這里,環(huán)境的準備并沒有結(jié)束,在創(chuàng)建項目的時候,angularJs6.x還用到了git命令,如果沒有安裝,就會報錯說git命令沒找到,因此我們還需要安裝git.因為我比較喜歡新的軟件,所以直接裝了git2.x:</pre>
<pre style="margin-left:36.0pt;text-indent:-18.0pt;mso-list:l2 level1 lfo3">1. yum install https://centos7.iuscommunity.org/ius-release.rpm</pre>
<pre style="margin-left:36.0pt;text-indent:-18.0pt;mso-list:l2 level1 lfo3">2. yum install git2u</pre>
<pre style="margin-left:36.0pt;
<pre style="text-indent:24.0pt;
mso-char-indent-count:2.0">環(huán)境準備好后,我們開始創(chuàng)建項目并運行:</pre>
<pre style="margin-left:60.0pt;text-indent:-18.0pt;
mso-list:l0 level1 lfo4">1. ng new conk-out</pre>
<pre style="margin-left:60.0pt;
text-indent:-18.0pt;mso-list:l0 level1 lfo4">2. cd conk-out</pre>
<pre style="margin-left:60.0pt;text-indent:
-18.0pt;mso-list:l0 level1 lfo4">3. ng serve –open</pre>