Share
Embed
Transcript
94 slides
-
ࣗݾհ 2019 APN AWS Top Engineersೝఆ AWSೝఆ 2017/5 ΫϥεϝιουJoin
ࠓͷۀɿDevelopers.IO Cafeͷཧը໘ɺAPI Angular5͋ͨΓ͔Β͡Ίͨ(2018ࠒ) ΞαΠϯ͞ΕͨҊ݅ͰSPAΛ࡞Δඞཁ͕͋Γɺ ϝϯόʔ͕AngularΛ͍ͬͯͨͷ͕͖͔͚ͬ ܦྺ ଜ ༞ೋ(28) CXࣄۀຊ෦ॴଐ େࡕΦϑΟεࡏ੶ -
"OHVMBSͷجຊใ wϦϦʔεɿલͷ"OHVMBS+4ɺ"OHVMBS݄ w࠷৽൛ɿόʔδϣϯʢʣ࣌ w։ൃମ੍ɿ(PPHMFͱίϛϡχςΟ wݴޠɿ5ZQF4DSJQU w࠾༻ࣄྫɿྺ࢙͋ΔେاۀͰͷ࣮͕ଟΊɺ($1$POTPMF 'JSFCBTF https://www.madewithangular.com/categories/angular/ اۀ
63- .JDSPTPGU IUUQTXXXP⒏DFDPNBQQT BVUI 'PSCFT IUUQTXXXGPSCFTDPN #.8 IUUQTpOEBEFBMFSCNXDPNBV 7.8BSF IUUQTDMBSJUZEFTJHO https://whouse.angular.jp/ -
8FCελϯμʔυͳٕज़ͱੑ͕ߴ͍ w&$."4DSJQU ͷߏจͰ࣮͞Ε͍ͯΔ w&4.PEVMFTʹରԠ w8FC"OJNBUJPOT"1* w8FC$PNQPOFOUT w&41SPQTBM w%FDPSBUPST w0CTFSWBCMFT
w;POFT ಠࣗ࿏ઢͰͳ͘ɺ Webͷඪ४ٕज़৽ٕज़Λ࠾༻ -
ϑϧελοΫ wఏڙϥΠϒϥϦ wجຊతͳͷҎ֎ʹ443ɺ18"ɺ8FC$PNQPOFOUTͳͲఏڙ w։ൃπʔϧपลڥʹؔ͢Δͷ͋Δ wϝϦοτ wϥΠϒϥϦબఆͷίετ͕ݮΔ wόʔδϣϯΞοϓʹΑΔෆ۩߹͕গͳ҆͘ఆ w͙͢ʹ։ൃʹͱΓ͔͔ΕΔ @angular/core
@angular/common @angular/animations @angular/forms @angular/router @angular/elements @angular/material @angular/platform-server @angular/service-worker ... -
ྫɿςετϑϨʔϜϫʔΫΛ+FTUʹมߋ wσϑΥϧτͰΠϯετʔϧ͞ΕΔ,BSNB͔Β+FTUʹมߋ w$-*͔ΒίϚϯυͰมߋྃɺґଘؔߟྀ͞ΕΔ https://dev.classmethod.jp/client-side/angular-jest-setup/ ❯ npm install -g @briebug/jest-schematic
❯ ng g @briebug/jest-schematic:add ❯ ng add @briebug/jest-schematic -
ίϯϙʔωϯτ wίϯϙʔωϯτͷ࡞Γํ͕ײతͰΘ͔Γ͍͢ w!$PNQPOFOUͰίϯϙʔωϯτΛఆٛ w࣮ଶΫϥε wTFMFDUPS͕ίϯϙʔωϯτͷλά໊ ίϯϙʔωϯτΛ͏ଆ(html) ίϯϙʔωϯτΛఆٛ͢Δଆ(ts) @Component({ selector:
'app-test', template: `<p>Name: {{ name }}</p>` }) export class TestComponent { @Input() name: string; } <app-test name="devio"></app-test> -
ίϯϙʔωϯτ wίϯϙʔωϯτͷ࡞Γํ͕ײతͰΘ͔Γ͍͢ w!$PNQPOFOUͰίϯϙʔωϯτΛఆٛ w࣮ଶΫϥε wTFMFDUPS͕ίϯϙʔωϯτͷλά໊ ίϯϙʔωϯτΛ͏ଆ(html) ίϯϙʔωϯτΛఆٛ͢Δଆ(ts) @Component({ selector:
'app-test', template: `<p>Name: {{ name }}</p>` }) export class TestComponent { @Input() name: string; } <app-test name="devio"></app-test> -
ίϯϙʔωϯτ wίϯϙʔωϯτͷ࡞Γํ͕ײతͰΘ͔Γ͍͢ w!$PNQPOFOUͰίϯϙʔωϯτΛఆٛ w࣮ଶΫϥε wTFMFDUPS͕ίϯϙʔωϯτͷλά໊ ίϯϙʔωϯτΛ͏ଆ(html) ίϯϙʔωϯτΛఆٛ͢Δଆ(ts) @Component({ selector:
'app-test', template: `<p>Name: {{ name }}</p>` }) export class TestComponent { @Input() name: string; } <app-test name="devio"></app-test> -
ίϯϙʔωϯτ wίϯϙʔωϯτͷ࡞Γํ͕ײతͰΘ͔Γ͍͢ w!$PNQPOFOUͰίϯϙʔωϯτΛఆٛ w࣮ଶΫϥε wTFMFDUPS͕ίϯϙʔωϯτͷλά໊ ίϯϙʔωϯτΛ͏ଆ(html) ίϯϙʔωϯτΛఆٛ͢Δଆ(ts) @Component({ selector:
'app-test', template: `<p>Name: {{ name }}</p>` }) export class TestComponent { @Input() name: string; } <app-test name="devio"></app-test> -
ίϯϙʔωϯτ wίϯϙʔωϯτͷ࡞Γํ͕ײతͰΘ͔Γ͍͢ w!$PNQPOFOUͰίϯϙʔωϯτΛఆٛ w࣮ଶΫϥε wTFMFDUPS͕ίϯϙʔωϯτͷλά໊ ίϯϙʔωϯτΛ͏ଆ(html) ίϯϙʔωϯτΛఆٛ͢Δଆ(ts) @Component({ selector:
'app-test', template: `<p>Name: {{ name }}</p>` }) export class TestComponent { @Input() name: string; } <app-test name="devio"></app-test> ੜ͞ΕΔDOM -
ςϯϓϨʔτߏจɹͦͷ wσʔλόΠϯσΟϯάΛαϙʔτ wγϯϓϧͰ؆୯ɹ<>Λ͚ͭΔ͚ͩ wϓϩύςΟʹೖ͢Δ wଐੑʹೖ͢Δ wΫϥεΛ͚ͭ֎͢͠ΔɺӈลͷධՁ݁Ռ wελΠϧΛ༩͢Δ @Component({ selector:
'app-test', template: ` <input [value]='name'> <div [attr.role]='role'></div> <div [class.large]='isLarge'></div> <div [style.width.px]='mySize'></div>` }) export class TestComponent { name = 'devio'; role = 'main'; isLarge = true; mySize: 16; } -
ςϯϓϨʔτߏจɹͦͷ wΠϕϯτϋϯυϦϯάɿΫϦοΫΠϕϯτͳͲ wγϯϓϧͰ؆୯ɹΠϕϯτ໊Λ ͰғΉ͚ͩ wFWFOUͰؔͰΠϕϯτใ͕ͱΕΔ @Component({ selector: 'app-test', template:
`<button (click)='onClick($event)'></button>` }) export class TestComponent { onClick(e: MouseEvent) { console.log(e); } } औΕͨΠϕϯτใ -
OHVQEBUF͕༏ल wϥΠϒϥϦಉ࢜ͷґଘؔΈͯ͘ΕΔ wQBDLBHFKTPOΛղੳ͠ɺߋ৽ՄೳͳύοέʔδΛදࣔ We analyzed your package.json, there are
some packages to update: Name Version Command to update -------------------------------------------------------------------------------- @angular/cdk 7.3.7 -> 8.0.0 ng update @angular/cdk @angular/cli 7.2.4 -> 8.0.1 ng update @angular/cli @angular/core 7.2.15 -> 8.0.0 ng update @angular/core @angular/material 7.3.7 -> 8.0.0 ng update @angular/material rxjs 6.3.3 -> 6.5.2 ng update rxjs There might be additional packages that are outdated. Run "ng update --all" to try to update all at the same time. ex) v7 => v8 -
5ZQF4DSJQUͷԸܙ w੩తͳܕ wܕϕʔεͷ%*͕Մೳ wܕͷ͓͔͛Ͱίʔυ͕υΩϡϝϯτʹͳΓৗʹίʔυͱυΩϡϝϯτ͕Ұக͢ Δʢ"OHVMBSͷυΩϡϝϯτʣ w$PNQJMFSDIFDL wίϯύΠϥνΣοΫʹΑΔόάͷࠞೖΛݮͤ͞Δ w-BOHVBHF4FSWJDF -BOHVBHF4FSWFS1SPUPDPM
wܕͷ͓͔͛ͰɺมΦϒδΣΫτ͕ͲΜͳϓϩύςΟΛ͔࣋ͭΘ͔ΔͨΊɺ ΤσΟλͷࢧԉ͕Ͱ͖Δɺೖྗิδϟϯϓ -
ߏཁૉ w1MBUGPSN NBJOUT w"QQMJDBUJPOɺ.PEVMFΛ࣮ߦ͢Δڥ w.PEVMF wSPPUͷ.PEVMFBQQNPEVMFUT wίϯϙʔωϯτͳͲΛ·ͱΊͨͷ w͍͍ͨػೳͷ.PEVMFΛJNQPSU
Application Platform Module Module Module Module Components Directives Pipes Services -
ΫΠοΫελʔτ w"OHVMBS$-*ΛΠϯετʔϧ wϓϩδΣΫτ࡞ wΞϓϦέʔγϣϯΛϩʔΧϧ࣮ߦ ❯ npm install -g @angular/cli
❯ ng new demo ? Would you like to add Angular routing? Yes ? Which stylesheet format would you like to use? CSS ❯ cd demo ❯ ng serve 10% building 3/3 modules 0 activeℹ ňwdsʼn: Project is running ** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ ** ℹ ňwdmʼn: Compiled successfully. -
ը໘ͷ෦Ͱ͋ΔίϯϙʔωϯτͷՃ w$-*͔ΒίϯϙʔωϯτΛ࡞ wΦϓγϣϯͰΠϯϥΠϯʹ͢Δ͜ͱՄ ❯ ng g component test --inlineStyle
--inlineTemplate ❯ ng g component test -
ςετ-JOUɺϏϧυ༻ͷίϚϯυ͋Δ wςετMJOUઃఆ͞Ε͓ͯΓɺڥߏஙෆཁ wϏϧυίϚϯυ͋Γɺ)5.- +4ΛʮEJTUʯʹग़ྗ wσϓϩΠίϚϯυ͋Γɺ؆୯ʹ'JSFCBTFͳͲʹσϓϩΠՄೳ w4ͷσϓϩΠBXTDMJ͔Β͕؆୯ ❯ ng build
❯ ng build --prod ❯ ng deploy ❯ aws s3 sync dist s3://<bucket> --delete ❯ ng lint ❯ ng e2e ❯ ng test -
͍ํ wΠϯετʔϧ w͍͍ͨίϯϙʔωϯτͷϞδϡʔϧΛJNQPSU FYBQQNPEVMFUT wλάΛهࡌ FYBQQDPNQPOFOUIUNM ❯ ng
add @angular/material import { MatSliderModule } from '@angular/material/slider'; … @NgModule ({.... imports: [..., MatSliderModule, …] }) <mat-slider min="1" max="100" step="1" value="1"></mat-slider> -
"OHVMBS'MFY-BZPVU w$44'MFYCPYΛσΟϨΫςΟϒͰࢦఆͰ͖ΔΑ͏ʹͨ͠ϥΠϒϥϦ wϨΠΞτϨεϙϯγϒରԠΛDTTΛ͔͔ͣʹ؆୯ʹ࣮Ͱ͖Δ w$44ͷϑΝΠϧΛߦͬͨΓདྷͨΓ͠ͳͯ͘Α͍ wରൣғ͕Θ͔Γ͍͢ <div fxLayout="row"> #fxlayout:boxͷํΛܾΊΔ <div
fxFlex="10%"></div> #fxflex:্هͰܾΊͨboxͷ෯orߴ͞ΛܾΊΔ <div fxFlex="10%"></div> <div fxFlex="80%"></div> </div> https://github.com/angular/flex-layout/wiki -
ઃఆྫ wQBUIͱίϯϙʔωϯτΛඥ͚͍ͯΔ wDBO"DUJWBUF<"ENJO(VBSE>ͱ͢Δ͚ͩͰೝূػೳΛ͚ͭΕΔ import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router'; import { TopComponent } from './component/top/top.component'; import { AdminGuard } from './auth/admin.guard'; const routes: Routes = [ {path: '',component: TopComponent}, {path: 'admin', loadChildren: () => import('./module/admin/admin.module').then(m => m.AdminModule), canActivate: [AdminGuard] } ]; export class AppRoutingModule {} -
ಈతʹϑΥʔϜͷՃɾআ͕Ͱ͖Δ w'PSN"SSBZʹQVTI͢Δ͜ͱͰՃ wSFNPWF"UͰϑΥʔϜআ addItem(eventForm: FormGroup, index: number) { this.itemsFormArray(eventForm,
index).push(this.initItemForm()); } initItemForm(): FormGroup { return this.fb.group({ store_code: [''], item_id: [''], stock: [''] }); } deleteItem(index: number, itemIndex: number) { this.itemsFormArray(index).removeAt(itemIndex); } Ճ࣌ͷϑΥʔϜ ϑΥʔϜΛՃ͢Δؔ ϑΥʔϜΛআ͢Δؔ -
ϦΞϧλΠϜʹόϦσʔγϣϯνΣοΫͯ͠ΤϥʔΛදࣔ initNewEventForm(eventsData: Events[]) { return this.fb.group({ event_code: [ '',
[ Validators.required, Validators.pattern('^[A-Z0-9][A-Z0-9_]+$'), Validators.maxLength(24), Validators.minLength(2), this.duplicateEventCodeValidator('event_code') ] ], available: [false] }); <mat-error *ngIf="eventForm.get('event_code').hasError('maxlength')"> {{ eventForm.get('event_code') .getError('maxlength').requiredLength }}จࣈҎԼͰೖྗ͍ͯͩ͘͠͞ɻ </mat-error> ςϯϓϨʔτ(html) ίϯϙʔωϯτ(ts) -
·ͱΊ w"OHVMBS w5ZQF4DSJQUͰܕ҆શ wϑϧελοΫ wίϯϙʔωϯτࢦͰ։ൃ͕؆୯ wόʔδϣϯΞοϓ͕؆୯Ͱ҆ఆ wരͰཧը໘Λͭ͘ΔͨΊʹ w"OHVMBS$-*Λ͍͜ͳ͢ w"OHVMBS.BUFSJBMͰ͔͚ͣʹ͍͍͔Μ͡ͷσβΠϯʹ
wςʔϒϧͷϖʔδωʔγϣϯɺιʔτɺϑΟϧλʔ؆୯ʹ࣮Ͱ͖Δ wཧը໘ͷ։ൃͰΑ͔ͬͨͱ͜Ζ wϧʔςΟϯάͰೝূ੍ޚͳͲ؆୯ʹ࣮Ͱ͖Δ w'PSN·ΘΓ͕ͱͯศར