Slide 1

Slide 1 text

AngularとSpring bootで 遊んでみる 2017.06.24 @KANJAVA PARTY

Slide 2

Slide 2 text

Who? Name: Masui Masanori Twitter: @masanori_msl Blog: vaguely http://mslgt.hatenablog.com/ GitHub: https://github.com/masanori840816

Slide 3

Slide 3 text

やりたいこと 前:Angular 後ろ:Spring boot(+Doma2+PostgreSQL) で、Webページを作る。 (情報の定期更新、ログイン、お問い合わせetc.)

Slide 4

Slide 4 text

Demo

Slide 5

Slide 5 text

Routing ボタンクリックでページ(Component)切り替え

Slide 6

Slide 6 text

Routing ①app.component ②main-page.component ③top-banner.component ③top-news.component ②を切り替える

Slide 7

Slide 7 text

app.routing.ts const appRoutes: Routes = [ { path: '', component: MainPageComponent }, { path: 'menulist', component: MenulistPageComponent }, { path: 'contact', component: ContactPageComponent }]; export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes);

Slide 8

Slide 8 text

ページ遷移 Home ● 「location.href=“/”」でも遷移可能だが、 ページがリロードされてしまう

Slide 9

Slide 9 text

サーバー側のRouting @Controller public class MainController { @RequestMapping(value = {"/", "/menulist", "/contact"}) public View redirect() { return new InternalResourceView("/index.html"); } }

Slide 10

Slide 10 text

Demo サーバー側からJSONを受け取って表示

Slide 11

Slide 11 text

サーバー側からJSONを受け取って表示 @RestController public class CrudController { @GetMapping(value = {"/topnewslist"}) public List topNewsList() { List topNewsItems = new ArrayList<>(); // 値をセット return topNewsItems;

Slide 12

Slide 12 text

サーバー側からJSONを受け取って表示 export class TopNewsComponent implements OnInit { newsList: TopNews[]; constructor(private http_: Http) { http_.get("/topnewslist") .map(response => response.json()) .subscribe(gotNews => this.newsList = gotNews); } }

Slide 13

Slide 13 text

サーバー側からJSONを受け取って表示
{{news.createdDate}}
{{news.title}}
{{news.article}}
アイテム数分枠内の部分が繰り返し表示される

Slide 14

Slide 14 text

CSS Grid Layout .top-news-item-area{ display: grid; /* Grid layoutを有効にする */ /* 左から順に1行目、2行目の高さを指定 */ grid-template-rows: 50px 100px; /* 左から順に1列目、2列目の幅を指定 */ grid-template-columns: 20% 1fr; }

Slide 15

Slide 15 text

CSS Grid Layout .top-news-item-date{ /* 1行目から3行目まで(つまり2行全て)を指定する */ grid-row: 1 / 3; /* 1列目から2列目まで(つまり1列目)を指定する */ Grid-column: 1 / 2; border: 1px solid #000; } 〜省略〜

Slide 16

Slide 16 text

課題 WARNING in ./src/app/top-news/top-news.component.css (Emitted value instead of an instance of Error) autoprefixer: /home/XXX/AnimeCrudSample/anime-crud-sample/src/app/top- news/top-news.component.css:20:5: IE supports only grid-row with / and span. You should add grid: false option to Autoprefixer and use some JS grid polyfill for full spec support @ ./src/app/top-news/top-news.component.ts 33:17-52 @ ./src/app/app.module.ts @ ./src/main.ts @ multi ./src/main.ts

Slide 17

Slide 17 text

課題 IEがgrid-row、grid-columnのセル指定方法の 一部を対応していないため、 それを使っている箇所全てに対して警告が 表示される/(^o^)\ (tslint.jsonをいじればいけそうだけど、チョットキモチワルイ)

Slide 18

Slide 18 text

● Typescriptなので型型してて馴染みやすい ● HTML、Script、CSS、テストが Component単位で分けられるのでシンプル ● 半年に一度のメジャーバージョン更新は不安 (ただしver.4は2018年までサポート予定) Angularを触ってみた感想

Slide 19

Slide 19 text

まとめ あれこれ考えず、 興味のあるものを好きなだけ取り入れて遊ぶのは   楽しい!

Slide 20

Slide 20 text

Angular Tutorial: Tour of Heroes with Angular-CLI (https://github.com/ng-japan/hands-on/tree/master/courses/tutorial) Angular 2 Cookbook - O'Reilly Media (http://shop.oreilly.com/product/9781785881923.do) Routing & Navigation -Angular (https://angular.io/guide/router) 参考

Slide 21

Slide 21 text

Spring bootr はじめての Spring Boot (https://www.kohgakusha.co.jp/books/detail/978-4-7775-1969-9) InternalResourceView (Spring Framework 4.3.9.RELEASE API) (http://docs.spring.io/spring-framework/docs/current/javadoc- api/org/springframework/web/servlet/view/InternalResourceView.html) Natural routes with path variables in spring-boot modular project does not work · Issue #68 · spring-guides/tut-spring-security-and-angular-js · GitHub (hhttps://github.com/spring-guides/tut-spring-security-and-angular- js/issues/68#issuecomment-187675742) 参考

Slide 22

Slide 22 text

CSS Grid Layout CSS グリッドレイアウト - CSS – MDN (https://developer.mozilla.org/ja/docs/Web/CSS/CSS_Grid_Layout) グリッド レイアウト (Windows) - msdn.aspx (https://msdn.microsoft.com/ja-jp/library/hh673533(v=vs.85).aspx) CSS Grid Layout Module Level 1 (https://www.w3.org/TR/css-grid-1/) CSS Grid Layout を極める!(基礎編) - Qiita (http://qiita.com/kura07/items/e633b35e33e43240d363) 参考

Slide 23

Slide 23 text

Thank you!