前言
接觸angular後其實真的很少寫jQuery,但很多時候拿到的html版可能是UI設計師所提供的,或者是花錢買的樣板,所以免不了要用jQuery寫入一些效果,本篇就簡單介紹一些如何在angular-cli專案加入第三方的.js .css.如何建立範本請參考 [Angular2] 建立專案範本
webpack
angular2是個模組化的開發方式,透過angular-cli所建置的專案已改由system.js改由webpack,以往要在angular2專案加入webpack,你必需要去了解webpack的建置環境,這對於一個全端工程師來說是個很焦慮的事XD,因為webpack要懂得的東西還真的不少,好在angular-cli已幫我們整合好,只要懂得用他的指令即可,而angular-cli相關webpack設定檔都至於node_modules底下,而webpack本身還有許多額外的套件,如果要增加的話不建議直接改node_modules這些設定檔,可在專案底下加入會比較彈性一點。
angular.cli.json
webpack會將我們相依的程式及模組打包成一隻.js減少request,而以下就介紹如何在專案下加入jQuery及bootstrap
先用yarn將jQuery及bootstrap安裝回來
# yarm是完全相依npm的套件管理工具,執行上比npm快非常多,可參考此篇文章$ yarn add jQuery bootstrap
package.json

在angular.cli.json 加入路徑
"styles": [
"styles.css",
"../node_modules/bootstrap/dist/css/bootstrap.min.css"
],
"scripts": [
"../node_modules/jquery/dist/jquery.min.js"
],
接著我們app.component.html加入一個bootstrap的Button (強烈建議編輯器要安裝snippet套件快速開發)

ng serve 啟動本機伺服器 可以看到已套用bootstrap

接著在app.component.ts加入jQuery試試

這時你會發現 $ 字號有毛毛蟲 這是因為Typescript是強行別的開發方式,檢查會變得較為嚴謹,任何開發尚未定義的變數都會在編譯時期就出錯。
而要讓Typescript看得懂 $ 字號為jQuery其實只要宣告一下就好了:
declare var $:any;
TypeScript With jQuery
而宣告成any還不夠帥,且每支檔案都要宣告一次還挺麻煩的,我們可以將此宣告移到一個全域的地方,
並且載入Typescript的jQuery設定檔定義檔,讓開發起來更順手
安裝jQuery Typescript定義檔:
$ yarn add @types/jquery
找到src/tsconfig.js,有關Typescript的設定都會在這檔案,加入types"types": [
"jquery"
]
接著回到app.componet.ts,會看到有關jQuery語法都開始會有智慧提示功能 (VS Code Rock!!)

在執行一次ng serve,即可看到jQuery正常執行

原則上Typescript用第三方函示庫就要有相對應的.d.ts定義檔,如果該函示庫如果沒有定義檔也可以自行製作一個
可參考保哥的教學影片 https://www.youtube.com/watch?v=_9fUQus6EqQ
或者是可以考慮在src/typings.d.ts進行全域的宣告也可
--
本次範例程式 : https://github.com/kyleap/angular-learn-sample
AngularJS is a toolset for building the framework most suited to your application development. It is fully extensible and works well with other libraries. Every feature can be modified or replaced to suit your unique development workflow and feature needs. Read on to find out how.
回覆刪除AngularJS Training in Chennai
我一直以為有個套件叫 [jQuery.Bootstrap]
回覆刪除看了3星期才了解jquery是jquery, bootstrap是bootstrap
謝謝提醒,已調整
刪除I simply wanted to write down a quick word to say thanks to you for those wonderful tips and hints you are showing on this site.
回覆刪除Click here:
Angularjs training in chennai
Click here:
angularjs training in bangalore
Click here:
angularjs training in online
I have visited this blog first time and i got a lot of informative data from here which is quiet helpful for me indeed.
回覆刪除Click here:
Microsoft azure training in chennai
Click here:
Microsoft Azure training in online
Thanks for the informative article. This is one of the best resources I have found in quite some time. Nicely written and great info. I really cannot thank you enough for sharing.
回覆刪除Blueprism training in Chennai
Blueprism training in Bangalore
Blueprism training in Pune
Blueprism training in tambaram
Blueprism training in annanagar
Blueprism training in velachery
Blueprism training in marathahalli
AWS Training in chennai
AWS Training in bangalore
I accept there are numerous more pleasurable open doors ahead for people that took a gander at your site.we are providing ReactJs training in Chennai.
回覆刪除For more details: ReactJs training in Velachery | ReactJs training in chennai
Information from this blog is very useful for me, am very happy to read this blog Kindly visit us @ Luxury Watch Box | Shoe Box Manufacturer | Candle Packaging Boxes
回覆刪除And indeed, I’m just always astounded concerning the remarkable things served by you. Some four facts on this page are undeniably the most effective I’ve had.
回覆刪除C C++ Training in Chennai |Best C C++ Training course in Chennai
linux Training in Chennai | Best linux Training in Chennai
Unix Training in Chennai | Best Unix Training in Chennai
uipath training in chennai | Best uipath training in chennai
Rprogramming Training in Chennai | Best Rprogramming Training in Chennai
Hi,
回覆刪除Good job & thank you very much for the new information, i learned something new. Very well written. It was sooo good to read and usefull to improve knowledge. Who want to learn this information most helpful. One who wanted to learn this technology IT employees will always suggest you take big data hadoop training in bangalore. Because big data course in Bangalore is one of the best that one can do while choosing the course.
the information you provided is more useful to us blockchain online training india
回覆刪除very nice.....!
回覆刪除inplant training in chennai
inplant training in chennai
inplant training in chennai for it
italy web hosting
afghanistan hosting
angola hosting
afghanistan web hosting
bahrain web hosting
belize web hosting
india shared web hosting
nice..
回覆刪除inplant training in chennai
inplant training in chennai
inplant training in chennai for it
hosting
india hosting
india web hosting
iran web hosting
technology 11 great image sites like imgur hosting
final year project dotnet server hacking what is web hosting
macao web hosting
nice...................
回覆刪除inplant training in chennai
inplant training in chennai
inplant training in chennai for it
algeeria hosting
angola hostig
shared hosting
bangladesh hosting
botswana hosting
central african republi hosting
shared hosting
nice blogggssss...!
回覆刪除internship in chennai for ece students
internships in chennai for cse students 2019
Inplant training in chennai
internship for eee students
free internship in chennai
eee internship in chennai
internship for ece students in chennai
inplant training in bangalore for cse
inplant training in bangalore
ccna training in chennai
good blogggssss...!
回覆刪除internship in chennai for ece students
internships in chennai for cse students 2019
Inplant training in chennai
internship for eee students
free internship in chennai
eee internship in chennai
internship for ece students in chennai
inplant training in bangalore for cse
inplant training in bangalore
ccna training in chennai
nice information....
回覆刪除winter internship for engineering students
internship for mca students
inplant training for eee students
inplant training for eee students/
java training in chennai
internships for eee students in hyderabad
ece internship
internship certificate for mechanical engineering students
internship in nagpur for computer engineering students
kaashiv infotech internship
internship for aeronautical engineering students in india 2019
nice information......
回覆刪除ree internship in bangalore for computer science students
internship for aeronautical engineering
internship for eee students in hyderabad
internship in pune for computer engineering students 2018
kaashiv infotech internship fees
industrial training certificate format for mechanical engineering students
internship report on machine learning with python
internship for biomedical engineering students in chennai
internships in bangalore for cse
internship in coimbatore for ece
Such a unique content. Highly appreciate the skills. keep going with the awesome work. Thank You. Web Designing Course Training in Chennai | Web Designing Course Training in annanagar | Web Designing Course Training in omr | Web Designing Course Training in porur | Web Designing Course Training in tambaram | Web Designing Course Training in velachery
回覆刪除I’m using the same blog platform like yours, and I’m having difficulty finding one? Thanks.leave some kore related to this blog.
回覆刪除Ai & Artificial Intelligence Course in Chennai
PHP Training in Chennai
Ethical Hacking Course in Chennai Blue Prism Training in Chennai
UiPath Training in Chennai
It is a great platform to learn.Thank you so much. Java training in Chennai | Certification | Online Course Training | Java training in Bangalore | Certification | Online Course Training | Java training in Hyderabad | Certification | Online Course Training | Java training in Coimbatore | Certification | Online Course Training | Java training in Online | Certification | Online Course Training
回覆刪除Thanks for the informative article. This is one of the best resources I have found in quite some time. Nicely written and great info. I really cannot thank you enough for sharing.
回覆刪除Digital Marketing Training in Chennai
Digital Marketing Course in Chennai
Learn Amazon Web Services for excellent job opportunities from Infycle Technologies, the Excellent AWS Training in Chennai. Infycle Technologies gives the most trustworthy AWS course in Chennai, with full hands-on practical training from professional trainers in the field. Along with that, the placement interviews will be arranged for the candidates, so that, they can meet the job interviews without missing them. To transform your career to the next level, call 7502633633 to Infycle Technologies and grab a free demo to know more
回覆刪除seo fiyatları
回覆刪除saç ekimi
dedektör
instagram takipçi satın al
ankara evden eve nakliyat
fantezi iç giyim
sosyal medya yönetimi
mobil ödeme bozdurma
kripto para nasıl alınır
bitcoin nasıl alınır
回覆刪除tiktok jeton hilesi
youtube abone satın al
gate io güvenilir mi
binance referans kimliği nedir
tiktok takipçi satın al
bitcoin nasıl alınır
mobil ödeme bozdurma
mobil ödeme bozdurma
perde modelleri
回覆刪除sms onay
mobil ödeme bozdurma
nft nasıl alınır
ankara evden eve nakliyat
trafik sigortası
dedektör
SİTE KURMA
aşk kitapları
smm panel
回覆刪除Smm Panel
İs İlanlari
instagram takipçi satın al
hirdavatciburada.com
BEYAZESYATEKNİKSERVİSİ.COM.TR
servis
tiktok jeton hilesi indir
作者已經移除這則留言。
回覆刪除作者已經移除這則留言。
回覆刪除Merry Christmas from the Fallon's!! (The girl with the pink hair is of no relation)," Fallon teases. Never miss a story. Christmas Message for Wife
回覆刪除instagram takipçi satın al
回覆刪除