Component என்பது ஒரு UI Block ஆகும்.ஒரு Page ஆனது நிறைய Component-யை கொண்டிருக்கும்.
ஒரு Component-யை உங்களுக்கு எந்த இடத்தில் பயன்படுத்த விரும்பிர்களோ அந்த இடத்தில் உங்களால் பயன்படுத்த முடியும்.
Component ஒரு directive ஆகும்.
(HTML+TYPESCRIPT+CSS) இந்த மூன்றும் சேர்ந்து உருவாகுவது தான் Component ஆகும்.
@Component என்பது ஒரு class decorator ஆகும்.
@Component என்று கொடுத்து இதனுள் கொடுக்கப்படுவதை ஒரு Component-ஆக எடுத்து கொள்ளப்படுகிறது.
@Component என்பது @angular/core என்ற library-யின் உள்ளே இருக்கிறது.
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
Selector என்பது Component-யின் பெயர் ஆகும்.
templateUrl என்று கொடுத்தால் அதனுள் HTML file path-னினை கொடுக்க வேண்டும்.
styleUrls என்று கொடுத்தால் அதனுள் css file path-னினை கொடுக்க வேண்டும்.
@Component({
selector: 'app-root',
template: ` <h2>I Love JavaScript </h2> `
})
Selector என்பது Component-யின் பெயர் ஆகும்.
template என்று கொடுத்தால் அதனுள் HTML Code-னினை எழுத வேண்டும்.
style என்று கொடுத்தால் அதனுள் css Code-னினை எழுத வேண்டும்.
நாம் ஒரு component-யை உருவாக்க வேண்டுமென்றால் அதற்கு ஒரு command உள்ளது.இந்த command-யை பயன்படுத்தி தான் component-யை உருவாக்க முடியும்.
Command Syntax
ng g c Component_ Name
g என்பது generate ஆகும்.
c என்பது component ஆகும்.
ex:
ng g c header
header என்பது Component_ Name ஆகும்.
No comments:
Post a Comment