import { Component } from '@angular/core';
import {ParentComponent} from './parent.component';
@Component({
selector: 'my-app',
template: `<parent></parent>`
})
export class AppComponent {
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { ParentComponent } from './parent.component';
import { ChildComponent } from './child.component';
@NgModule({
imports: [
BrowserModule,
FormsModule,
],
declarations: [
AppComponent,
ParentComponent,
ChildComponent
],
bootstrap: [ AppComponent ]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app.module';
platformBrowserDynamic().bootstrapModule(AppModule);
<!DOCTYPE html>
<html>
<head>
<title>Angular Tour of Heroes</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="styles.css">
<!-- Polyfills for older browsers -->
<script src="https://unpkg.com/core-js/client/shim.min.js"></script>
<script src="https://unpkg.com/zone.js@0.6.25?main=browser"></script>
<script src="https://unpkg.com/reflect-metadata@0.1.8"></script>
<script src="https://unpkg.com/systemjs@0.19.39/dist/system.src.js"></script>
<script src="https://cdn.rawgit.com/angular/angular.io/b3c65a9/public/docs/_examples/_boilerplate/systemjs.config.web.js"></script>
<script>
System.import('app').catch(function(err){ console.error(err); });
</script>
</head>
<body>
<my-app>Loading...</my-app>
</body>
</html>
import {Component, EventEmitter, Output} from '@angular/core';
@Component({
moduleId: module.id,
selector: 'child',
templateUrl: 'child.component.html'
})
export class ChildComponent{
@Output()
childChanged = new EventEmitter<string>();
onChange(value:string){
this.childChanged.emit(value)
}
}
import {Component} from '@angular/core';
import {ChildComponent} from './child.component';
@Component({
moduleId: module.id,
selector: 'parent',
templateUrl: 'parent.component.html',
directives: [ChildComponent]
})
export class ParentComponent{
public inputFromChild: string;
}
<div>
<input type="text" #childInput (keyup)="onChange(childInput.value)">
</div>
<label for="parent">Parent</label>
<p>{{inputFromChild}}</p>
<label for="child">Child Input</label>
<child id="child" (childChanged)="inputFromChild = $event"></child>