|
1 |
| -<p align="center"> |
2 |
| - <img src="https://res.cloudinary.com/angularclass/image/upload/v1431925418/webpackAndangular2_dwhus9.png" alt="Webpack and Angular 2" width="500" height="320"/> |
3 |
| -</p> |
| 1 | +# Angular 2: Authentication sample. |
4 | 2 |
|
5 |
| -# Angular2 Webpack Starter [](https://gitter.im/angular-class/angular2-webpack-starter?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) |
| 3 | +This sample shows how to create an angular 2 app that: |
| 4 | +* Has **lots of different routes** |
| 5 | +* Performs **authentication with JWTs** |
| 6 | +* **Calls APIs** authenticated and not. |
| 7 | +* Extends the **RouterOutlet** for route pipeline changes. |
6 | 8 |
|
7 |
| -> A starter kit featuring [Angular 2](https://angular.io) ([Router](https://angular.io/docs/js/latest/api/router/), [Forms](https://angular.io/docs/js/latest/api/forms/), [Services](https://gist.github.com/gdi2290/634101fec1671ee12b3e#_follow_@AngularClass_on_twitter)), [TypeScript](http://www.typescriptlang.org/), and [Webpack](http://webpack.github.io/) by [AngularClass](https://angularclass.com). |
| 9 | +> You can **learn more about how it works [in this blogpost](https://auth0.com/blog/2015/05/14/creating-your-first-real-world-angular-2-app-from-authentication-to-calling-an-api-and-everything-in-between/)** |
8 | 10 |
|
9 |
| -> If you're looking for Angular 1.x please use [NG6-starter](https://github.com/angular-class/NG6-starter) |
| 11 | +## Running it |
10 | 12 |
|
11 |
| -This repo serves as an extremely minimal starter for anyone looking to get up and running with Angular 2 and TypeScript. Using a [Webpack](http://webpack.github.io/) for building our files and assisting with boilerplate. |
12 |
| -* Best practice in file organization for Angular 2. |
13 |
| -* Ready to go build system using Webpack for working with TypeScript. |
14 |
| - |
15 |
| -### Quick start |
16 |
| -> Clone/Download the repo then edit `app.ts` inside [`/src/app/components/app.ts`](/src/app/components/app.ts) |
17 |
| -
|
18 |
| -```bash |
19 |
| -$ npm start # then open your browser and go to http://localhost:8080 |
20 |
| -``` |
21 |
| - |
22 |
| - |
23 |
| -## File Structure |
24 |
| -We use the component approach in our starter. This is the new standard for developing Angular apps and a great way to ensure maintainable code by encapsulation of our behavior logic. A component is basically a self contained app usually in a single file or a folder with each concern as a file: style, template, specs, e2e, and component class. Here's how it looks: |
25 |
| -``` |
26 |
| -angular2-webpack-starter/ |
27 |
| - ├──public/ * static assets are served here |
28 |
| - │ ├──lib/ * static libraries |
29 |
| - │ │ └──traceur-runtime.min.js * ignore this file. This is needed to polyfill the browser to for ES6 features to similarly |
30 |
| - │ │ |
31 |
| - │ ├──favicon.ico * replace me with your own favicon.ico |
32 |
| - │ ├──service-worker.js * ignore this. Web App service worker that's not complete yet |
33 |
| - │ ├──robots.txt * for search engines to crawl your website |
34 |
| - │ ├──human.txt * for humans to know who the developers are |
35 |
| - │ │ |
36 |
| - │ └──index.html * Index.html: where we place our script tags |
37 |
| - │ |
38 |
| - ├──src/ * our source files that will be compiled to javascript |
39 |
| - │ ├──app/ * WebApp folder |
40 |
| - │ │ ├──bootstrap.ts * entry file for app |
41 |
| - │ │ │ |
42 |
| - │ │ ├──components/ * where most of components live |
43 |
| - │ │ │ ├──todo.ts * an example of a component using a service and forms |
44 |
| - │ │ │ ├──dashboard.ts * a simple Component with a simple Directive example |
45 |
| - │ │ │ │ |
46 |
| - │ │ │ ├──home/ * example component as a folder |
47 |
| - │ │ │ │ ├──home.ts * how you would require your template and style files |
48 |
| - │ │ │ │ ├──home.css * simple css file for home styles |
49 |
| - │ │ │ │ └──home.html * simple html file for home template |
50 |
| - │ │ │ │ |
51 |
| - │ │ │ └──app.ts * App.ts: entry file for components |
52 |
| - │ │ │ |
53 |
| - │ │ ├──services/ * where we keep our services used throughout our app |
54 |
| - │ │ │ ├──TodoService.ts * an example of a simple service |
55 |
| - │ │ │ └──services.ts * where we gather our injectables from our services |
56 |
| - │ │ │ |
57 |
| - │ │ └──directives/ * where we keep our directives used throughout our app |
58 |
| - │ │ ├──Autofocus.ts * another simple directive to fix a problem with the router |
59 |
| - │ │ └──directives.ts * where we gather our directives from our directives |
60 |
| - │ │ |
61 |
| - │ └──common/ * where common files used throughout our app |
62 |
| - │ ├──shadowDomInjectables.ts * determind if the user is on chrome and use ShadowDom |
63 |
| - │ ├──jitInjectables.ts * turn on Just-In-Time Change Detection |
64 |
| - │ ├──formInjectables.ts * services exported by angular/forms which is the FormBuilder |
65 |
| - │ └──BrowserDomAdapter.ts * ignore this. we need to set the DomAdapter to the browser |
66 |
| - │ |
67 |
| - ├──typings/ * where tsd defines it's types definitions |
68 |
| - │ ├──_custom/ * where we define our custom types |
69 |
| - │ │ ├──ng2.d.ts * where we patch angular2 types with our own types until it's fixed |
70 |
| - │ │ └──custom.d.ts * we include all of our custom types here |
71 |
| - │ │ |
72 |
| - │ ├──angular2/ |
73 |
| - │ │ └──angular2.d.ts * our Angular 2 type definitions |
74 |
| - │ │ |
75 |
| - │ ├──es6-promise/ |
76 |
| - │ │ └──es6-promise.d.ts * ES6 promises type definitions |
77 |
| - │ │ |
78 |
| - │ ├──rx/ |
79 |
| - │ │ ├──rx-lite.d.ts * rx-lite type definitions |
80 |
| - │ │ └──rx.d.ts * rx type definitions |
81 |
| - │ │ |
82 |
| - │ └──tsd.d.ts.ts * our main file for all of our type definitions |
83 |
| - │ |
84 |
| - ├──tsconfig.json * config that webpack uses for typescript |
85 |
| - ├──tsd.json * config that tsd uses for managing it's definitions |
86 |
| - ├──package.json * what npm uses to manage it's dependencies |
87 |
| - └──webpack.config.js * our webpack config |
88 |
| -``` |
89 |
| - |
90 |
| -# Getting Started |
91 |
| -## Dependencies |
92 |
| -What you need to run this app: |
93 |
| -* `node` and `npm` (`brew install node`) |
94 |
| -* Ensure you're running the latest versions Node `v0.12.2`+ and NPM `2.10.0`+ |
95 |
| - |
96 |
| -Once you have those, you should install these globals with `npm install -global`: |
97 |
| -* `webpack` (`npm install -global webpack`) |
98 |
| -* `webpack-dev-server` (`npm install -global webpack-dev-server`) |
99 |
| - |
100 |
| -## Installing |
101 |
| -* `fork` this repo |
102 |
| -* `clone` your fork |
103 |
| -* `npm install` to install all dependencies |
104 |
| -* `npm run server` to start the server |
105 |
| - |
106 |
| -## Running the app |
107 |
| -After you have installed all dependencies you can now run the app. Run `npm server` to start a local server using `webpack-dev-server` which will watch, build (in-memory), and reload for you. The port will be displayed to you as `http://localhost:8080`. |
108 |
| - |
109 |
| -### server |
110 |
| -```bash |
111 |
| -$ npm run server |
112 |
| -``` |
113 |
| - |
114 |
| -### build files |
115 |
| -```bash |
116 |
| -$ npm run build |
117 |
| -``` |
118 |
| - |
119 |
| -### watch and build files |
120 |
| -```bash |
121 |
| -$ npm run watch |
122 |
| -``` |
123 |
| - |
124 |
| -# TypeScript |
125 |
| -> To take full advantage of TypeScript with autocomplete you would have to install it globally and use an editor with the correct TypeScript plugins. |
126 |
| -
|
127 |
| -## Use latest TypeScript compiler |
128 |
| -TypeScript 1.5 beta includes everything you need. Make sure to upgrade, even if you installed TypeScript previously. |
129 |
| - |
130 |
| - $ npm install -global typescript@^1.5.0-beta |
131 |
| - |
132 |
| -## .d.ts Typings |
133 |
| -The typings in `typings/` are partially autogenerated, partially hand |
134 |
| -written. All the symbols should be present, but probably have wrong paramaters |
135 |
| -and missing members. Modify them as you go. |
136 |
| - |
137 |
| - $ npm install -global tsd |
138 |
| - > You may need to require `reference path` for your editor to autocomplete correctly |
139 |
| - ``` |
140 |
| - /// <reference path="../../typings/tsd.d.ts" /> |
141 |
| - /// <reference path="../custom_typings/ng2.d.ts" /> |
142 |
| - ``` |
143 |
| - Otherwise including them in `tsd.json` is prefered |
144 |
| - |
145 |
| -## Use a TypeScript-aware editor |
146 |
| -We have good experience using these editors: |
147 |
| - |
148 |
| -* [Visual Studio Code](https://code.visualstudio.com/) |
149 |
| -* [Webstorm 10](https://www.jetbrains.com/webstorm/download/) |
150 |
| -* [Atom](https://atom.io/) with [TypeScript plugin](https://atom.io/packages/atom-typescript) |
151 |
| -* [Sublime Text](http://www.sublimetext.com/3) with [Typescript-Sublime-Plugin](https://github.com/Microsoft/Typescript-Sublime-plugin#installation) |
152 |
| - |
153 |
| -## Frequently asked questions |
154 |
| -* Why we are using traceur? This is due to Angular 2 not being fully migrated to TypeScript and will be removed soon. |
155 |
| -* What's the current browser support for Angular 2 Alpha? as of version 2.0.0-alpha.26: Chrome (43, 44, 45), Firefox (37, 39, 40), IE 11, Safari 8, iOS 8, Android 5.1 (Chrome Mobile 39). |
156 |
| -* What is the TypeScript warning "Value of type 'typeof Directive' is not callable. Did you mean to include 'new'?"? This is an error with the typings defined in DefinitelyTyped (please ignore until it's fixed) |
157 |
| - |
158 |
| -### Todo |
159 |
| -- [ ] production/development environments |
160 |
| -- [ ] testing |
161 |
| -- [ ] e2e |
162 |
| -- [ ] production services examples |
163 |
| -- [ ] hot-component-reloading |
164 |
| - |
165 |
| -# Starter Kit Support and Questions |
166 |
| -> Contact us anytime for anything about this repo |
167 |
| -
|
168 |
| -* [Gitter: angular-class/angular2-webpack-starter](https://gitter.im/angular-class/angular2-webpack-starter) |
169 |
| -* [Twitter: @AngularClass](https://twitter.com/AngularClass) |
170 |
| - |
171 |
| -___ |
172 |
| - |
173 |
| -enjoy — **AngularClass** |
174 |
| - |
175 |
| -<br><br> |
176 |
| - |
177 |
| -[](https://angularclass.com) |
178 |
| -##[AngularClass](https://angularclass.com) |
179 |
| -> Learn Angular in 2 days from the best |
| 13 | +Just install `node` and run `npm install` and then `npm start` :boom:. |
0 commit comments