app.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'app';
stock = ""
}
app.component.html
<h1>组件间的通信</h1>
<div>我是父组件</div>
<div>
<input type="text" placeholder="请输入股票代码" [(ngModel)]="stock">
<app-order [stockCode]="stock" [amount]="100"></app-order>
</div>
order.component.ts
import { Component, OnInit, Input} from '@angular/core';
@Component({
selector: 'app-order',
templateUrl: './order.component.html',
styleUrls: ['./order.component.css']
})
export class OrderComponent implements OnInit {
@Input()
stockCode:string;
@Input()
amount: number
constructor() { }
ngOnInit() {
}
}
order.component.html
<div>
我是子组件
</div>
<div>
买{{amount}}手{{stockCode}}股票
</div>
是不是在module里面没有引入FormsModule