컴포넌트 데이터바인딩 하기 2
부모에서 선언한 변수를 자식 컴포넌트에서 사용하기
ng g c child
<h1>{{ title }}</h1>
<app-child [item]="data"></app-child>
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
title = 'ang-data';
data = 10;
}
<h1>{{ title }}</h1>
<app-child [item]="data"></app-child>
import { Component, OnInit, **Input** } from '@angular/core';
@Component({
selector: 'app-child',
templateUrl: './child.component.html',
styleUrls: ['./child.component.scss']
})
export class ChildComponent implements OnInit {
constructor() { }
ngOnInit(): void {
}
}
// @Input() item=0 추가
import { Component, OnInit, **Input** } from '@angular/core';
@Component({
selector: 'app-child',
templateUrl: './child.component.html',
styleUrls: ['./child.component.scss']
})
export class ChildComponent implements OnInit {
constructor() { }
@Input() item=0
ngOnInit(): void {
}
}