Following are the key points described later in this article:
Components are at the heart of Angular 2 apps. A component in Angular2 is used to represent a View along with associated logic (encapsulated as a Class), which will get executed based on interaction with that view. Additionally, a component could call/invoke one or more services which can be “dependency injected” into it.
Typically, an HTML page could consist of different view slots, each representing different data. One or more such different views could get associated with its own components. Further, a component in an Angular 2 app could have child components as well. An angular app could have one top-level component and several internal sub-components. The app get started with bootstraping top-level component. Take a look at following sample app:
angular 2 components
In above app, following could be observed:
The code could look like following:
<marksheet>
<searchbox></searchbox>
<searchresults></searchresults>
</marksheet>
Does the above resemble like Angular 1 directives. Well, simply speaking, Angular 2 components is nothing short of Angular 1 directives.
A Component in Angular2 is associated with a View and a Class encapsulating the business logic. Take a look at following code sample for a component written with TypeScript language:
@Component({
selector: 'hello-world'
})
@View({
template: '<div>Hello {{name}}</div>' })
class HelloComponent({
name: 'Calvin Hobbes'
})
bootstrap(HelloComponent);
The above component could be placed inside an HTML with tag such as <hello-world></hello-world>. In the above component, following could be observed:
Last updated: 25th Jan, 2025 Have you ever wondered how to seamlessly integrate the vast…
Hey there! As I venture into building agentic MEAN apps with LangChain.js, I wanted to…
Software-as-a-Service (SaaS) providers have long relied on traditional chatbot solutions like AWS Lex and Google…
Retrieval-Augmented Generation (RAG) is an innovative generative AI method that combines retrieval-based search with large…
The combination of Retrieval-Augmented Generation (RAG) and powerful language models enables the development of sophisticated…
Have you ever wondered how to use OpenAI APIs to create custom chatbots? With advancements…