2 is a bigger number than 1, True Story.
Why the changes
Why the changes
Components are how things are built in angular.
These are the same
ngSwitch for conditional layouts
ngClass for multiple classes
*ngFor for repeating an element
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { AppComponent } from './app.component';
import { ChildComponent } from './child/child.component';
import { FriendsService } from './friends.service';
@NgModule({
declarations: [
AppComponent,
ChildComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule
],
providers: [FriendsService],
bootstrap: [AppComponent]
})
export class AppModule { }
<h1>
{{title}}
</h1>
<app-child></app-child>
@Component({
selector: 'app-child',
templateUrl: './child.component.html',
styleUrls: ['./child.component.css']
})
export class ChildComponent implements OnInit {
title: string;
friends: Array<string>;
newFriend: string;
friendName: string;
test: string;
constructor(private friendsService: FriendsService) {}
getFriends(): void {
this.friends = this.friendsService.friends;
}
addFriend(friend: string): void {
this.friendsService.friend = friend;
this.newFriend = '';
}
ngOnInit() {
this.title = 'Child Class!';
this.getFriends();
this.test = 'foo';
}
}
See component API in Angular 1.5