startup project for a Angular2 app
based on: https://angular.io/docs/ts/latest/quickstart.html
Start:
- npm install
- npm run postinstall
- npm start
happy coding
import { Component } from '@angular/core';
@Component({
selector: 'app-home',
templateUrl: 'app/home/home.component.html'
})
export class HomeComponent {...}
add this in module.ts
declarations: [
HomeComponent,
import { Injectable } from '@angular/core';
@Injectable()
export class ItemService {...}
inject in where you use it:
constructor(private itemServer: ItemService)
add this in module.ts
providers: [
ItemService
or:
constructor(@Injectable('mail') private mailService)
providers: [ { provice:'mail', useClass:MailService} ]
place, where the routing will be shown:
<router-outlet></router-outlet>
enter this in module.ts
import { RouterModule } from '@angular/router';
imports: [
RouterModule.forRoot([
{ path: "", component: HomeComponent },
{ path: "about", component: AboutComponent }
])
]
link a a route:
<a routerLink="about">home</a> |
<li *ngFor"let item of getItems() | itemFilter:filterText">
import { PipeTransform, Pipe } from '@angular/core'
@Pipe({
name:'itemFilter'
})
export class ItemFilterPipe implements PipeTransform {
transform(list, filterBy) {
in module.ts:
declarations: [ ItemFilterPipe ]
<li *ngFor="let msg of mail.messages">{{msg}}</li>
send values to a child component
<app-item
*ngFor="let msg of mail.messages
[param]="msg >
</app-item>
class ItemComponent {
@Input() param;
}
{{param}}
[] input
() output
<text type="text" [(ngModel)]=param