Upgrade to Pro — share decks privately, control downloads, hide ads and more …

モダンAngularJS @ GDG中国2014.12.6

OKUNOKENTARO
December 06, 2014

モダンAngularJS @ GDG中国2014.12.6

2014年12月6日発表分の資料をSlideShareより再掲。
http://www.slideshare.net/armorik83/angularjs-141206

OKUNOKENTARO

December 06, 2014
Tweet

More Decks by OKUNOKENTARO

Other Decks in Programming

Transcript

  1. 禸ך暴ꞿ ˖ 䎃剢傈חꟚ⪵ׁ׸׋OHFVSPQFחג
 ؽآָّٝ爙ׁ׸׋ ˖ ٌتٝـٓؐؠ׾䠐陎
 &4 &$."4DSJQU ד圓眠ծ&4ד׮ⵃ欽〳腉 ˖

    "U4DSJQUהְֲ䭁䓸鎉铂
 㘗➰ֽծ،ظذ٦ءّٝծ㣐鋉垷⻉פך佄䴂 ˖ KR-JUFך䐖姺ծػؿؓ٦وٝأぢ♳
 K2VFSZ⢪欽♶〳הז׷׻ֽדכזְ ˟䎃剢植㖈ך䞔㜠
  2. "OHVMBS+4 5ZQF4DSJQU ˖ 5ZQF4DSJQUכ&4ך圓俑׾⯓遤㼪Ⰵ׃גְ׷ ˖ DMBTT NPEVMFזו ˖ ׮׍׹׿㢌䳔ׅ׷ךדծ&4ךـٓؐؠד⹛ֻ ˖

    ꫼涸㘗➰ֽה؝ٝػ؎ٓח״׷ؒٓ٦ثؑحؙ ˖ 㣐鋉垷Ꟛ涪קו؝ٝػ؎ٓך佄䴂ָꅾ銲ח ˖ "OHVMBSד䲿周ׁ׸׷"U4DSJQUח➙ַ׵䢪׸׷ז׵ֿ׸ ˖ 5ZQF4DSJQU荈⡤ծⰋגך+BWB4DSJQUח崞ַׇ׷ךד
 鋙ִגְֶג䴦כזְ
  3. ׋׌׃剑㊣דכזְ ˖ $broadcast, $onכ剑㊣ך،فٗ٦ثדכזְ ˖ 俑㶵⴨ٔذٕٓדװ׶ה׶ׅ׷ַ׵ד֮׷ ! ˖ *%&ך佄䴂׮「ֽחְֻ ˖

    鍑寸岀ה׃גכծ$broadcast荈⡤׾
 ׅץגTFSWJDFדٓحؾؚٝ׃ծًاحسה׃ג䪔ֲ
 $onח剅ֻ؎كٝزせ׮ծ׉ךTFSWJDFַ׵《䖤ׅ׷
 ًاحسせז׵*%&ָ钠陎׃ג酡㸣׃גֻ׸׷ $scope.$broadcast('EventNameString', args);
  4. 穗꿀锑ַ׵ך%%0 ˖ %%0%JSFDUJWF%FGJOJUJPO0CKFDU
 ֮ךꞿְꞿְؔفءّٝծ%JSFDUJWFכ꬗⦜ה䙼׻׸׷♧殢ך⾱㔓 ˖ SFTUSJDU%JSFDUJWFך邌鎸倯岀ծ㾩䚍せַծ銲稆せַ˘ ˖ ֿ׸כ"㾩䚍せה׃גה&銲稆せה׃ג
 ׌ֽ鋙ִגֶֻ֮הכ⢪׻זְ ˖

    TDPQF4DPQF׾欰䧭ׅ׷ַⰟ剣ׅ׷ַ ˖ 䌢חؔـآؙؑز٥ٔذٕٓד䭷㹀
 A new "isolate" scope. ˖ Ⱏ剣⵸䲿ך鏣鎘כ鼘ֽ׋קֲָ葺ְ scope: { attr: '@myAttr', foo: '=myFoo', bar: '@myBar' },
  5. 4FSWJDFה'BDUPSZ ˖ 4FSWJDF؝ٝأزؙٓةꟼ侧׾♷ִג"OHVMBS+4ָ
 ؎ٝأةٝأ׾欰䧭
 4JOHMFUPOה׃ג婍׷ ˖ 'BDUPSZ♷ִ׋ꟼ侧׾
 㹋遤׃䨱׶⦼׾鵤ׅ function MyComponent()

    { // ... } ! angular.module('myModule') .service('MyComponent', MyComponent); ! angular.module('myModule') .factory('MyComponent', function() { return MyComponent; });
  6. .PEFMה*OKFDU ˖ .7$ׅץג׾"OHVMBS+4דװ׹ֲהׅ׷ַ׵
 ٗحؙ؎ָٝ孡חַַ׏גֻ׷ ˖ "OHVMBS+4כ׋׌⽃ח3&45 7JFX.PEFM 5FNQMBUF
 ח暴⻉ ˖

    .PEFMծؽآطأٗآحؙכ"OHVMBS+4"1*׾♧ⴖろתזְ
 秪磏ז+4ה׃ג㹋鄲
 ⟎ח"OHVMBS+4ָهءٍ׏ג׮➭'8ד⢪ְת׻ׇ׷״ֲח
  7. ˖ %*،ظذ٦ءّٝכ䗳׆剅ֹת׃׳ֲ
 ׁ׮זֻלNJOJGZ儗ח岛ֹתׅ ˖ %*،ظذ٦ءّٝהכծ؎ٝأةٝأ欰䧭儗ח
 ؎ٝآؙؑزׅ׷4FSWJDF׾寸㹀ׅ׷׋׭ך䞔㜠 ˖ 䒷侧׾俑㶵⴨דػ٦أ׃ג铣׿ד׷׵׃ְ׈˘
 ה㢌䡾㹋鄲ָ鑧겗חז׶ת׃׋ָծ㣐㢌״׹׃ֻזְדׅ 1.

    minify対策 angular.module('myModule') .service('MyService', function(OtherService) { // ... ↑͜͜ʹແ͍!! }); ! angular.module('myModule') .service('MyService', ['OtherService', function(OtherService) { // ... }]);
  8. ˖ ⦐➂涸חכֿ׏׍ך剅ֹ倯ךקֲָ㥨ֹ ! ! ! ˖ .service()ⰻחꞿղה剅ֻ״׶طأز׮幾׏גأحؗٔ ˖ "OHVMBS+4ַ׵ng-strict-diָ鷄⸇ׁ׸׋
 ،ظذ٦ءّٝ鎸鶢怩׸׾ؒٓ٦ה׃ג䭷䶯ׅ׷

    1. minify対策 function MyService(OtherService) { // ... } MyService.$inject = ['OtherService']; ! angular.module('myModule') .service('MyService', MyService); <body ng-app="myApp" ng-strict-di> ... </body>
  9. ˖ ng-repeatװ%JSFDUJWFךcompile, link׾㢳欽׃גְ׷ה
 넝然桦ד幉✉ׅ׷ ˖ K2VFSZ׮⢘欽׃גٔحثז6*׾邌植׃״ֲ
 הַ䙼ְ㨣׭׷הծ劍䖉ׅ׷銲稆ָundefined׌׏׋הַؠٓ ˖ ⹞׾אַ׬תדכ嗚鏾ָ㣐㢌 ˖

    ⯓傈剢傈ⰕꟚ׃׋2JJUB"EWFOU$BMFOEBSך䬴鎸✲
 חגծֿךװװֿ׃ְⳢ椚갫׾Ⰻגתה׭גְתׅ
 ׈מ׀⿫罋ח 5. directive処理順
  10. 植㖈ךر؍ؙٖزٔ root ├── Gruntfile.js ├── app │ ├── bower_components │

    ├── my_components │ │ └── * │ ├── my_modules │ │ └── * │ ├── favicon.ico │ ├── fonts │ ├── images │ ├── robots.txt │ ├── scripts │ │ ├── app.js │ │ ├── controllers │ │ ├── directives │ │ ├── filters │ │ ├── injectors │ │ ├── modules │ │ ├── routes.js │ │ ├── run.js │ │ └── services │ ├── styles │ │ ├── sass │ │ └── screen.css │ └── views │ ├── 404.html │ ├── index.html │ ├── partials │ └── parts ├── bower.json ├── common │ └── * ├── doc ├── e2e.conf.js ├── karma.conf.js │ ├── lib │ ├── bootstrap-models.js │ ├── config │ │ └── * │ ├── controllers │ │ └── * │ ├── middleware.js │ ├── models │ │ └── * │ └── routes.js ├── log ├── node_modules ├── package.json ├── server.js ├── test │ ├── client │ │ ├── e2e │ │ ├── mock │ │ └── spec │ └── server │ ├── mock │ └── spec ├── tsd.json └── typings ├── e2e.d.ts └── tsd.d.ts 㶵ָ㼭ֻׁגְׅתׇ׿
  11. ؝٦ر؍ؚٝ٥أة؎ٕ ˖ angular.module()ך剅ֹ倯׌הַծinjectך剅ֹ倯׌הַ
 ׫׿זֽ׏ֲֿغٓغٓ ˖ 剑ⴱח鋅׋ثُ٦زٔ،ٕךأة؎ٕד׉ךתת鹌׭ג׃תֲ؛٦أ
 ֿ׸כהג׮⽬זְ
 ثُ٦زٔ،ٕכꞿ劍鏣鎘׾䠐陎׃גְזְ ˖ ؚؚ׏׋׵侧珏겲ך؝٦ر؍ؚٝ٥أة؎ָٕ⳿גֻ׷


    BOHVMBSKTTUZMFHVJEF<嗚稊> ˖ ׉׸׵ח׮䊴כ֮׷ָծⰟ鸐׃ג鶢ץגְ׷✲갪׮֮׷ךד
 ׉ך鴟䖞ֲץֹ ˖ ⦐➂涸חכ function(){funtion(){function(){... ָ
 㜔ִ׵׸זְךדծ〳腉זꣲ׶䎂׵ח剅ְגְ׷
 ׉ך倯ָꬊず劍窃׫ךذأزװ䊴׃剏ִ׮׃װְׅ
  12. OQN CPXFS ˖ ZPBOHVMBSGVMMTUBDLָ欽䠐׃׋QBDLBHFKT׾ك٦أח׃גְ׷ ˖ ؝ىُصذ؍ך崧׸װ䐖׸גְזְַ׾鋅זָ׵傈ղ鑐遤ꐪ铎 ˖ OPEF@NPEVMFTכ
 express, lodash,

    log4js, mongoose,
 mongoose-auto-increment, passport זו ˖ CPXFS@DPNQPOFOUTכ
 angular, angular-animate, angular-ui-bootstrap,
 d3, es5-shim, jquery, lodash, node-uuid, underscore.string זו
  13. HSVOU ˖ ؽٕسخ٦ٕחכHSVOU׾⢪欽 ˖ &YQSFTT؟٦غך饯⹛װذأزծ؝ٝػ؎ٕזוծׅץגHSVOUח
 ⟣ׇגְ׷ ˖ connect-livereload, grunt-este-watch,
 grunt-express-server,

    grunt-karma,
 grunt-ng-annotate, grunt-ts, grunt-typedoc, karma, karma-phantomjs-launcher, load-grunt-tasks, protractor, time-gruntזו ˖ ♧⦐♧⦐铡僇דֹתׇ׿ָծJOKFDUך،ظذ٦ءّٝ鎸鶢׾荈⹛ ⻉ׅ׷grunt-ng-annotateכֶׅׅ׭
  14. ذأز ˖ OPEFKT⩎כ׉ךתת.PDIB
 "OHVMBS+4⩎כ,BSNB 1IBOUPN+4 +BTNJOF ˖ "OHVMBS+4Ⱅ䒭דכذأز٥ؿٖ٦يٙ٦ؙח
 +BTNJOF׾⹻׭גְ׷ָ.PDIBָ⹛ַזְ׻ֽדכזְ ˖

    &&ذأز1SPUSBDUPSחꟼ׃גכ
 +BTNJOFח✲㹋♳ꣲ㹀ׁ׸׷ ˖ ،؟٦ءّٝכQPXFSBTTFSU
 ٌحؙذأزכ4JOPO+4ծ+BTNJOF4QZ׾⢘欽
 ➙䖓4JOPO+4⩎ח♧劤⻉׃״ֲה䙼׏גְ׷
  15. ⿫罋项俱٥鎸✲갫♶ず ˖ OHFVSPQFIUUQOHFVSPQFPSH ˖ "OHVMBS+4ؕٝؿ؋ٖٝأO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MFS׾⢪׻׆ %JSFDUJWFDPOUSPMMFS׾欽ְ׷ ٌتٝAngularJS

    3 鋵㶨ד$TDPQFךⰟ剣כ⽬ꤹ ⡚穠さח⡲׶
 ؎كٝز꽀⹛׾䠐陎 ٌتٝAngularJS 4 ,BSNB 1SPUSBDUPSד ذأز׮䫙ַ׶זֻ ٌتٝAngularJS 5 "OHVMBSח⪒ִ׷ז׵ %JSFDUJWF׾琎噰涸ח荈⡲ ٌتٝAngularJS 7 $PSF"1*׾⢪ְװֻׅٓحف 荈⡲4FSWJDFד
 Ⳣ椚ךꅾ醱׾鼘ֽ׷ ٌتٝAngularJS 8 عو׶וֿ׹כ⯓➂ָعو׏ג׷ 縐׾䛊׸׆鹌׭ ٌتٝAngularJS 9 ػح؛٦آ盖椚ծؽٕسخ٦ٕד ؝ٝػؙزז㹋鄲ח㼔䙀 ٌتٝAngularJS 6 'BDUPSZח״׷JOKFDU׾崞欽׃ג "OHVMBS+4"1*׾
 ⢪׻זְⳢ椚כ㢩פ