Angularμ @Input
- λΆλͺ¨ μ»΄ν¬λνΈμμ μμ μ»΄ν¬λνΈλ‘ λ°μ΄ν°λ₯Ό μ λ¬ν λ μ¬μ©
- μμ μ»΄ν¬λνΈμ μμ μ μ μ νκ³ , λΆλͺ¨ μ»΄ν¬λνΈμμ κ°μ μ λ¬ν μ μλλ‘ νλ€.
- λΆλͺ¨ μ»΄ν¬λνΈμμ [childProperty]="parentValue"μ κ°μ΄ μμ±μ μ€μ νμ¬ μμ μ»΄ν¬λνΈμ κ°μ μ λ¬νλ€.
// parent.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'app-parent',
template: `
<div>
<app-child [childProperty]="parentValue"></app-child>
</div>
`,
})
export class ParentComponent {
parentValue = 'λΆλͺ¨μμ μ λ¬ν κ°';
}
// child.component.ts
import { Component, Input } from '@angular/core';
@Component({
selector: 'app-child',
template: `
<div>
<p>μμ μ»΄ν¬λνΈ μμ± κ°: {{ childProperty }}</p>
</div>
`,
})
export class ChildComponent {
@Input() childProperty: string;
}
Reactμ props
- Reactμ props λν λΆλͺ¨ μ»΄ν¬λνΈμμ μμ μ»΄ν¬λνΈλ‘ κ°μ μ λ¬ν λ μ¬μ©νλ€.
- propsλ propertyμ μ€λ§λ‘, html νκ·Έμ attributeμ ꡬλΆλλ€.
- React μ»΄ν¬λνΈλ ν¨μλ ν΄λμ€λ‘ ꡬνλ μ μμΌλ©°, ν¨μν μ»΄ν¬λνΈλ propsλ₯Ό νλΌλ―Έν°λ‘ λ°μ μ¬μ©νκ³ , ν΄λμ€ν μ»΄ν¬λνΈλ this.propsλ₯Ό ν΅ν΄ μ κ·Όνλ€.
- λΆλͺ¨ μ»΄ν¬λνΈμμ childProperty={parentValue}μ κ°μ΄ μμ±μ μ§μ νμ¬ μμ μ»΄ν¬λνΈμ κ°μ μ λ¬νλ€.
// ν¨μν μ»΄ν¬λνΈ
import React from 'react';
function ChildComponent(props) {
return (
<div>
<p>μμ μ»΄ν¬λνΈ μμ± κ°: {props.childProperty}</p>
</div>
);
}
// ν΄λμ€ν μ»΄ν¬λνΈ
import React, { Component } from 'react';
class ChildComponent extends Component {
render() {
return (
<div>
<p>μμ μ»΄ν¬λνΈ μμ± κ°: {this.props.childProperty}</p>
</div>
);
}
}
// λΆλͺ¨ μ»΄ν¬λνΈ
import React from 'react';
import ChildComponent from './ChildComponent';
function ParentComponent() {
const parentValue = 'λΆλͺ¨μμ μ λ¬ν κ°';
return (
<div>
<ChildComponent childProperty={parentValue} />
</div>
);
}
λ°μν
'Frontend > Angular vs React' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
Angular vs React | μλͺ μ£ΌκΈ° λ©μλμ λν΄μ (0) | 2023.12.06 |
---|---|
Angular vs React | μ ν리μΌμ΄μ μ§μ μ μ λν΄μ (0) | 2023.11.16 |
Angular vs React | λμ λ°μ΄ν° λ°μΈλ©μ λν΄μ (0) | 2023.11.15 |
Angular vs React | κ°μ DOMμ λν΄μ (0) | 2023.10.11 |
Angular vs React | 곡ν΅μ (0) | 2023.10.11 |