---
title: Angular 2 Starter Project
localeTitle: Угловой 2 стартовый проект
---
В этом учебнике будет создан чрезвычайно простой проект семян с Angular2. Мы начнем с самого базового приложения, а затем добавим немного больше функциональности.
## обзор
Угловые 2 приложения создаются путем создания HTML-шаблонов, содержащих угловую специфическую разметку. Классы затем создаются для управления шаблонами, и все обернуто в модуль, который вы объединяете для создания своего приложения. Эти модули называются **компонентами** .
Угловой интерпретирует эти модули и использует их для представления вашего приложения в браузере.
## Применение для начинающих
Давайте начнем с минимального приложения. Мы начнем с приложения, содержащего единственный модуль, единственное задание которого - отобразить некоторый текст.
Начнем с создания новой папки под названием «приложение».
```
$ mkdir app
```
Как уже упоминалось выше, наше приложение будет начинаться с одного модуля или **компонента** , который отобразит текст на экране. Мы можем использовать как чистый JavaScript, так и TypeScript для создания углового приложения 2. Используя TypeScript, он проще и удобнее в программировании. ![:wink:](//forum.freecodecamp.com/images/emoji/emoji_one/wink.png?v=2 ": Подмигивать:")
Давайте узнаем, как создать компонент с помощью TypeScript.
Создайте файл _`app.component.ts`_ как показано:
```
// app.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
template: '
`,
styles: [`
.counter {
width: 100%;
margin: auto;
background: darkgreen;
border-radius: 5px;
color: white;
padding: 20px;
text-align: center;
}
.counter h1 {
margin: 0;
padding: 20px;
font-size: 36px;
}
.counter button {
background: #f1c40f;
border: 0;
box-shadow: 0px 5px 0px #927608;
padding: 20px;
width: 100%;
outline: none;
border-radius: 5px;
color: darkgreen;
font-weight: bold;
}
.counter button:hover {
background: #a9890a;
cursor: pointer;
}
`]
})
export class IncrementClicker {
curClicks = 0;
incrementClicks() {
this.curClicks++;
}
}
```
Our component structure is similar to our previous one, but we've added a bit of functionality here. You will notice our class is no longer empty. We've added a variable to track the clicks as well as a function to increment them when the user clicks the button.
You can display properties from your class in your template using double braces such as: `{{ variableName }}`
We bind the button click event to our class function using Angulars Event Bindings.
```html
```
Notice that we've also added some styling to our components. This way everything is self-contained in this module. You may also include a `templateUrl` and/or `styleUrls` properties instead to extract the template and style rules to an external file and link them here.
Now we just need to update our `AppComponent` to include our new component:
```js
// app/app.component.ts
import { Component } from '@angular/core';
/* Nested Component */
import { IncrementClicker } from 'app/increment-clicker.component';
@Component({
selector: 'my-app',
directives: [IncrementClicker],
template: `
Free Code Camp Rocks!
`,
styles: [`
h1 { color: darkgreen; font-family: Arial, Helvetica, sans-serif;}
`]
})
export class AppComponent { }
```
To pull in our new `IncrementClicker` component we need to import it by including the class name as well as the location of the typescript file as we did on this line:
```js
import { IncrementClicker } from 'app/increment-clicker.component';
```
We then add the `IncrementClicker` *component* as a directive to the `AppComponent` module using:
```js
directives: [IncrementClicker],
```
Наконец, мы просто добавляем тег, к которому подключается наш компонент в шаблоне. Таким образом, селектор в нашем компоненте `IncrementClicker` будет соответствовать тегу, где мы хотим, чтобы он отображался.
`js template:`
# Бесплатные кодовые камни!
`,`
Наш компонент теперь включен в наше приложение!
\[Обновленный код
[ПРОСМОТРЕТЬ ПОЛНОЕ ПРИМЕНЕНИЕ](http://run.plnkr.co/plunks/BdvNONEmO3Jwg0EavX22/)