2015-10-14 20:25:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								include ../../../_includes/_util-fns
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-07 18:24:40 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								:marked
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  Let's start from zero and build a simple Angular 2 application in JavaScript.
							 | 
						
					
						
							
								
									
										
										
										
											2015-03-02 06:01:47 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-07-20 11:41:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								.callout.is-helpful
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  header Don't want JavaScript?
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  :marked
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    Although we're getting started in JavaScript, you can also write Angular 2 apps
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    in TypeScript and Dart by selecting either of those languages from the combo-box in the banner.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								:marked
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  We'll do it in six short steps
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  1. Create a project folder
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  1. Install essential libraries
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  1. Write the root component for our application in *app.js*
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  1. Bootstrap the app
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  1. Create an *index.html*
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  1. Run it
							 | 
						
					
						
							
								
									
										
										
										
											2015-07-20 11:41:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-03-02 06:01:47 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								.l-main-section
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  :marked
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ## Create a project folder
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    **Create a new folder** to hold our application project, perhaps like this:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ```
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-15 21:51:13 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    mkdir angular2-quickstart
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    cd    angular2-quickstart
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ```
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-15 21:51:13 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								.l-main-section
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  :marked
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ## Install essential libraries
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    We'll use the **npm package manager** to install packages for
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    the libraries and development tools we need:
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    >angular2 - the Angular 2 library.
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    >[live-server](https://www.npmjs.com/package/live-server "Live-server")
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    a static file server that reloads the browser when files change.
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    We could reference the libraries on the web or download them to our project.
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    That isn't a sustainable development process and package loading with npm is really
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    easy once we have it installed.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  .alert.is-helpful
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    :marked
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      Don't have npm? [Get it now](https://docs.npmjs.com/getting-started/installing-node "Installing Node.js and updating npm")
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      because we're going to use it now and repeatedly throughout this documentation.
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  :marked
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    **Open** a terminal window and enter these commands:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ```
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    npm init -y
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-18 14:31:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    npm i angular2@2.0.0-alpha.44 --save --save-exact
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    npm i live-server --save-dev
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ```
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    These commands both *install* the packages and *create* an npm configuration
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    file named `package.json`.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    The essence of our `package.json` should look like this:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-15 21:51:13 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  +makeJson('quickstart/js/package.json', { paths: 'name, version, dependencies, devDependencies'})
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  :marked
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    There is also a `scripts` section. **Find and replace** it with the following:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-15 21:51:13 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  +makeJson('quickstart/js/package.json', { paths: 'scripts'})
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  :marked
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    We've just extended our project world with a script command that we'll be running very soon.
							 | 
						
					
						
							
								
									
										
										
										
											2015-03-02 06:01:47 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								.l-main-section
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  :marked
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ##  Our first Angular component
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    Add a new file called *app.js* and paste the following lines:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-15 21:51:13 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  +makeExample('quickstart/js/app.js', 'class-w-annotations')
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  :marked
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    We're creating a visual component named **`AppComponent`** by chaining the
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    `Component` and `Class` methods that belong to the **global Angular namespace, `ng`**.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ```
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    var AppComponent = ng
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        .Component({...})
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        .Class({...})
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ```
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    The **`Component`** method takes a configuration object with two
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    properties. The `selector` property tells Angular that this is a component
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    controlling a host element named "my-app".
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    Angular creates and displays an instance of our `AppComponent`
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    wherever it encounters a `my-app` element.
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    The `template` property defines the visual appearance of the component.
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    We're writing the HTML template inline in this example.
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    Later we'll move the HTML to a view template file and
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    assign the template's filename to the `templateUrl` property.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    We'll prefer that practice for all but the most trivial templates.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    The **`Class`** method is where we implement the component itself,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    giving it properties and methods that bind to the view and whatever
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    behavior is appropriate for this part of the UI.
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    This component class has the bare minimum implementation:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    a *no-op* constructor function that does nothing because there is nothing to do.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    We'll see more interesting component classes in future examples.
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-03-02 06:01:47 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								.l-main-section
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  :marked
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ## Bootstrap the app
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    We need to do something to put our application in motion.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    Add the following to the bottom of the `app.js` file:
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-15 21:51:13 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  +makeExample('quickstart/js/app.js', 'bootstrap')
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  :marked
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    We'll wait for the browser to tell us that it has finished loading
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    all content and then we'll call the Angular `bootstrap` method.
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    The `bootstrap` method tells Angular to start the application with our
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    `AppComponent` at the application root.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    We'd be correct to guess that someday our application will
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    consist of more components arising in tree-like fashion from this root.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ### Wrapped in an IIFE
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    We don't want to pollute the global namespace.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    We don't need an application namespace yet.
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    So we'll surround the code in a simple IIFE
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ("Immediately Invoked Function Execution")
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    wrapper.
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    Here is the entire file:
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-15 21:51:13 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  +makeExample('quickstart/js/app.js', 'dsl')
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-03-03 13:50:44 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								.l-main-section
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  :marked
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ## Create an *index.html*
							 | 
						
					
						
							
								
									
										
										
										
											2015-03-02 06:01:47 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    **Add a new `index.html`** file to the project folder and enter the following HTML
							 | 
						
					
						
							
								
									
										
										
										
											2015-03-04 05:27:48 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-15 21:51:13 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  +makeExample('quickstart/js/index.html', null, 'index.html')(format="")
							 | 
						
					
						
							
								
									
										
										
										
											2015-03-03 13:50:44 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  .l-sub-section
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    :marked
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      Our app loads two script files in the `<head>` element:
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-27 16:03:15 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      >***angular2.sfx.dev.js***, the Angular 2 development library that puts
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      Angular in the global `ng` namespace.
							 | 
						
					
						
							
								
									
										
										
										
											2015-03-04 22:48:32 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      >***app.js***, the application JavaScript we just wrote.
							 | 
						
					
						
							
								
									
										
										
										
											2015-03-04 22:48:32 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      In the `<body>`, there's an element called `<my-app>`.
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      This is the placeholder for the *root* of the
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      application. Angular displays our application here.
							 | 
						
					
						
							
								
									
										
										
										
											2015-03-02 06:01:47 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								.l-main-section
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  :marked
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ## Run it!
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    We need a file server to serve the static assets of our application
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    (*index.html* and *app.js*).
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    For this example we'll use the **live-server** that we installed with `npm`
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    because it performs a live reload by default and it's
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    fun to watch the browser update as we make changes.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    Open a terminal (or Windows/Linux command line) and enter:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  pre.prettyprint.lang-bash
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    code npm start
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  .alert.is-helpful
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    :marked
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								       That's the `npm` command we added earlier to the `scripts` section of `package.json`
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  :marked
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    **live-server** loads the browser for us and refreshes the page as we make
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    changes to the application.
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    In a few moments, a browser tab should open and display
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  figure.image-display
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-15 21:51:13 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    img(src='/resources/images/devguide/quickstart/my-first-app.png' alt="Output of quickstart app")
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  :marked
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ### Make some changes
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    The `live-server` detects changes to our files and refreshes the browser page for us automatically.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    Try changing the message to "My SECOND Angular 2 app".
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    The `live-server` sees that change and reloads the browser.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    Keep `live-server` running in this terminal window and keep trying changes.
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    You can stop it anytime with `Ctrl-C`.
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    **Congratulations!  We are in business** ... and ready to take
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    our app to the next level.
							 |