17.10.2018 Views

Angular

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<br />

<br />

<br />

System.import('app').catch(function(err){ console.error(err); });<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

Your application will be rendered between the my-app tags.<br />

However, <strong>Angular</strong> still doesn't know what to render. To tell it that, we'll define AppComponent.<br />

Step 5<br />

Create a subfolder called app where we can define the components and services that make up our app. (In this<br />

case, it'll just contain the AppComponent code and main.ts.)<br />

mkdir app<br />

Step 6<br />

Create the file app/app.component.ts<br />

import { Component } from '@angular/core';<br />

@Component({<br />

selector: 'my-app',<br />

template: `<br />

{{title}}<br />

<br />

<br />

{{message}}<br />

<br />

<br />

`<br />

})<br />

export class AppComponent {<br />

title = "<strong>Angular</strong>2 example";<br />

messages = [<br />

"Hello World!",<br />

"Another string",<br />

"Another one"<br />

];<br />

}<br />

What's happening? First, we're importing the @Component decorator which we use to give <strong>Angular</strong> the HTML tag and<br />

template for this component. Then, we're creating the class AppComponent with title and messages variables that<br />

we can use in the template.<br />

Now let's look at that template:<br />

{{title}}<br />

<br />

GoalKicker.com – <strong>Angular</strong> 2 Notes for Professionals 13

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!