S
S
Skrolea2016-02-04 10:27:43
JavaScript
Skrolea, 2016-02-04 10:27:43

How to "use" Angular 2?

So I decided to try new technologies for a day. I installed angular2-webpack-starter and turned it on in a stupor.
I want to make a table component with pagination. For it, I will need (well, as I understand it) to declare a component, have a service (for the logic of issuing a page with pagination) and a directive for pagination buttons. Made a table folder, made a file:

import {Component} from 'angular2/core';
interface TableInterface {
  id: number;
  name: string;
}

@Component({
  selector: 'med-table',
  template:`
  <h1>Table</h1>
  <table>'
       <tbody>
       <tr *ngFor="#table of data">
       <td {{table.name}}></td>
       </tr>
       <tbody>
       </table>`,
  styles:[` `]
})
export class Table {
 public data = DATA;
  constructor() {
}
}
// Добавил из Heroes Tour
var DATA: TableInterface[] = [
  { "id": 11, "name": "Mr. Nice" },
  { "id": 12, "name": "Narco" },
  { "id": 13, "name": "Bombasto" },
  { "id": 14, "name": "Celeritas" },
  { "id": 15, "name": "Magneta" },
  { "id": 16, "name": "RubberMan" },
  { "id": 17, "name": "Dynama" },
  { "id": 18, "name": "Dr IQ" },
  { "id": 19, "name": "Magma" },
  { "id": 20, "name": "Tornado" }
];

And that is all. How can I connect this component to the home page? I made in component home.ts
import {Table} from '../components/table/table';
and in html tried to thrust
<med-table></med-table>
Nothing happened. Or do you still need to add a directive to the component and insert it into another component? Should it be imported into the target component? And how generally to connect the directive and components?
And what to do with the service? I will need to get data from somewhere. In the first Angular, I made a directive that itself received data from the view

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Osher, 2016-02-04
@miraage

Everything is described in the docs.
https://angular.io/docs/ts/latest/quickstart.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question