SlideShare a Scribd company logo
Understand Components in
Angular 2
AngularJs1.0 provide directive controllers,scope towrite acomponentswhichcontainsthe logic. In
AngularJs1.0 a componentscanbe combinationof directives,controllersandscope.
But inAngular2 Components are waytowrite elementsandlogicforapplication.
For designacomponentyourequire atleastone @Componentand one @Viewannotation.
@Componentannotationspecifieswhenacomponentis instantiatedmeans whenwe use component
inour viewthenitwill initializedthe componentandcalled contractorandrenderedthe view.
Whena componentisinstantiated,Angular
 Create DOM for the component.
 Load selectedtemplate intoDOM
 Injectobjectsandrenderview
 Today I am givingone example of components.
On followingexample when we use the <first-component></first-component>taginour View then
componentwill be create, constructorwillbe called andcomponentrendered.
Plnkr - http://plnkr.co/edit/IAQpVBPhgn1JSokQAux2?p=preview
Component Example in Angular 2
index.html
<!DOCTYPE html>
<html>
<head> <title>UnderstandComponentsinAngular 2 </title>
<script src="https://jspm.io/system@0.18.17.js"></script>
<script src="https://code.angularjs.org/2.0.0-alpha.37/angular2.min.js"></script>
<script>
System.config({
paths: {
'app.js':'app.js'
}
});
System.import('app.js');
</script>
</head>
<body>
<first-component></first-component>
</body>
</html>
app.es6.js
//Import Angular
import {Component,View,bootstrap} from 'angular2/angular2';
///Define a component
// Annotation section
//@Component annotations
@Component({
selector:'first-component'
})
//@View annotations
@View({
template:'<h1>Angular 2 - {{ message }}</h1> '
})
// AngularJs 2 component
class MyComponent{
name:string;
constructor() {
this.message = 'First Component';
}
}
bootstrap(MyComponent);
Thanks
www.codeandyou.com
http://www.codeandyou.com/2015/11/understand-
components-in-angular-2.html
Keywords - Understand Component in Angular 2, How to use Component in
Angular 2, component in Angular 2, Angular 2 component

More Related Content

PPTX
Code migration from Angular 1.x to Angular 2.0
PDF
Angular2 workshop
PPTX
Peggy angular 2 in meteor
PDF
The productive developer guide to Angular 2
PDF
Get rid of controllers in angular 1.5.x start using component directives
PDF
Angular2 - In Action
PPTX
Dive into Angular, part 4: Angular 2.0
PDF
Data Flow Patterns in Angular 2 - Sebastian Müller
Code migration from Angular 1.x to Angular 2.0
Angular2 workshop
Peggy angular 2 in meteor
The productive developer guide to Angular 2
Get rid of controllers in angular 1.5.x start using component directives
Angular2 - In Action
Dive into Angular, part 4: Angular 2.0
Data Flow Patterns in Angular 2 - Sebastian Müller

What's hot (20)

PDF
Angular 2 - An Introduction
PDF
Commit University - Exploring Angular 2
PDF
Angular 2 - The Next Framework
PPTX
Angular2 + rxjs
PDF
AngularJs Style Guide
PDF
AngularJS in practice
PPTX
AngularJS Fundamentals + WebAPI
PPTX
Angular 9
PPTX
What are the components in React?
PDF
Web components are the future of the web - Take advantage of new web technolo...
PDF
React with Ref
PDF
The productive developer guide to Angular 2
PDF
Dependency Injection pattern in Angular
ODP
Routing & Navigating Pages in Angular 2
PPTX
Angular 2.0 change detection
DOCX
Angular js getting started
PDF
Introduction to angular 2
PDF
AngularJS - dependency injection
PDF
Angular from Scratch
ODP
Angular 6 - The Complete Guide
Angular 2 - An Introduction
Commit University - Exploring Angular 2
Angular 2 - The Next Framework
Angular2 + rxjs
AngularJs Style Guide
AngularJS in practice
AngularJS Fundamentals + WebAPI
Angular 9
What are the components in React?
Web components are the future of the web - Take advantage of new web technolo...
React with Ref
The productive developer guide to Angular 2
Dependency Injection pattern in Angular
Routing & Navigating Pages in Angular 2
Angular 2.0 change detection
Angular js getting started
Introduction to angular 2
AngularJS - dependency injection
Angular from Scratch
Angular 6 - The Complete Guide
Ad

Similar to Understand components in Angular 2 (20)

PDF
AngularJS 2.0 Jumpstart
PPTX
Angular 2 KTS
PPTX
Introduction to Angular2
PPTX
An evening with Angular 2
PDF
Angular2 with type script
PDF
An Intro to Angular 2
PPTX
An afternoon with angular 2
PPTX
Angular%201%20to%20angular%202
PPTX
What’s new in angular 2 - From FrontEnd IL Meetup
PDF
Understanding Angular 2 - Shmuela Jacobs - Codemotion Milan 2016
PPTX
What’s new in angular 2
PDF
Angular 2 Crash Course
PDF
Exploring Angular 2 - Episode 1
PPTX
What's new in Angular 2?
ODP
Introduction to Angular 2
PPTX
Angular2v2
PPTX
Moving From AngularJS to Angular 2
PPT
Angular.ppt
PDF
angular fundamentals.pdf angular fundamentals.pdf
PDF
Angular2 tutorial
AngularJS 2.0 Jumpstart
Angular 2 KTS
Introduction to Angular2
An evening with Angular 2
Angular2 with type script
An Intro to Angular 2
An afternoon with angular 2
Angular%201%20to%20angular%202
What’s new in angular 2 - From FrontEnd IL Meetup
Understanding Angular 2 - Shmuela Jacobs - Codemotion Milan 2016
What’s new in angular 2
Angular 2 Crash Course
Exploring Angular 2 - Episode 1
What's new in Angular 2?
Introduction to Angular 2
Angular2v2
Moving From AngularJS to Angular 2
Angular.ppt
angular fundamentals.pdf angular fundamentals.pdf
Angular2 tutorial
Ad

More from codeandyou forums (17)

DOCX
How to validate server certificate
DOCX
How to call $scope function from console
DOCX
Understand routing in angular 2
DOCX
How to setup ionic 2
DOCX
MongoDB 3.2.0 Released
DOCX
Welcome to ionic 2
DOCX
What is JSON? Why use JSON? JSON Types? JSON Helpful Tools?
DOCX
How to install ssl certificate from .pem
DOCX
Protractor end-to-end testing framework for angular js
DOCX
How routing works in angular js
DOCX
How to use proxy server in .net application
DOCX
How to catch query string in angular js
DOCX
Different way to share data between controllers in angular js
DOCX
Angular.js interview questions
DOCX
How to set up a proxy server on windows
DOCX
What is $root scope in angularjs
DOCX
How to save log4net into database
How to validate server certificate
How to call $scope function from console
Understand routing in angular 2
How to setup ionic 2
MongoDB 3.2.0 Released
Welcome to ionic 2
What is JSON? Why use JSON? JSON Types? JSON Helpful Tools?
How to install ssl certificate from .pem
Protractor end-to-end testing framework for angular js
How routing works in angular js
How to use proxy server in .net application
How to catch query string in angular js
Different way to share data between controllers in angular js
Angular.js interview questions
How to set up a proxy server on windows
What is $root scope in angularjs
How to save log4net into database

Recently uploaded (20)

PDF
Understanding Forklifts - TECH EHS Solution
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PPTX
Log360_SIEM_Solutions Overview PPT_Feb 2020.pptx
PDF
System and Network Administraation Chapter 3
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
iTop VPN Free 5.6.0.5262 Crack latest version 2025
PPTX
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
PDF
top salesforce developer skills in 2025.pdf
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Nekopoi APK 2025 free lastest update
PDF
Digital Strategies for Manufacturing Companies
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
medical staffing services at VALiNTRY
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
Understanding Forklifts - TECH EHS Solution
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Log360_SIEM_Solutions Overview PPT_Feb 2020.pptx
System and Network Administraation Chapter 3
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Design an Analysis of Algorithms I-SECS-1021-03
Operating system designcfffgfgggggggvggggggggg
wealthsignaloriginal-com-DS-text-... (1).pdf
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
iTop VPN Free 5.6.0.5262 Crack latest version 2025
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
top salesforce developer skills in 2025.pdf
Odoo POS Development Services by CandidRoot Solutions
Navsoft: AI-Powered Business Solutions & Custom Software Development
Nekopoi APK 2025 free lastest update
Digital Strategies for Manufacturing Companies
Design an Analysis of Algorithms II-SECS-1021-03
Softaken Excel to vCard Converter Software.pdf
medical staffing services at VALiNTRY
Which alternative to Crystal Reports is best for small or large businesses.pdf

Understand components in Angular 2

  • 2. AngularJs1.0 provide directive controllers,scope towrite acomponentswhichcontainsthe logic. In AngularJs1.0 a componentscanbe combinationof directives,controllersandscope. But inAngular2 Components are waytowrite elementsandlogicforapplication. For designacomponentyourequire atleastone @Componentand one @Viewannotation. @Componentannotationspecifieswhenacomponentis instantiatedmeans whenwe use component inour viewthenitwill initializedthe componentandcalled contractorandrenderedthe view. Whena componentisinstantiated,Angular  Create DOM for the component.  Load selectedtemplate intoDOM  Injectobjectsandrenderview  Today I am givingone example of components. On followingexample when we use the <first-component></first-component>taginour View then componentwill be create, constructorwillbe called andcomponentrendered. Plnkr - http://plnkr.co/edit/IAQpVBPhgn1JSokQAux2?p=preview Component Example in Angular 2 index.html <!DOCTYPE html> <html> <head> <title>UnderstandComponentsinAngular 2 </title> <script src="https://jspm.io/[email protected]"></script> <script src="https://code.angularjs.org/2.0.0-alpha.37/angular2.min.js"></script> <script> System.config({ paths: { 'app.js':'app.js' } }); System.import('app.js'); </script> </head> <body> <first-component></first-component> </body> </html>
  • 3. app.es6.js //Import Angular import {Component,View,bootstrap} from 'angular2/angular2'; ///Define a component // Annotation section //@Component annotations @Component({ selector:'first-component' }) //@View annotations @View({ template:'<h1>Angular 2 - {{ message }}</h1> ' }) // AngularJs 2 component class MyComponent{ name:string; constructor() { this.message = 'First Component'; } } bootstrap(MyComponent);
  • 4. Thanks www.codeandyou.com http://www.codeandyou.com/2015/11/understand- components-in-angular-2.html Keywords - Understand Component in Angular 2, How to use Component in Angular 2, component in Angular 2, Angular 2 component