Skip to main content

Angular Basics

Angular is component based framework. Each page in application has different components and tied to the root component.

Each component has its view (html) , css(stylesheets), ts(typescript files containing logic), spec.ts (used for unit testing component)

Prerequisites:
------------
Download
- Node.js (Runtime for angular applications)
- npm (node package manager - to install dependencies for angular)
- angular cli (command line interface for generating, running angular projects)

Angular CLI Commands:
----------------------
ng new (creates a fresh application)
ng serve (starts the application on node server)
ng generate component (To create a new component)

Visual Code Commands:
Open a terminal window - Control + ~

Module vs Components:
--------------------
Each module may have one or more components.
Each component will have HTML, logic and Data.

Steps to create a component:

Create a component.
 - Naming convention for component : .component.ts
 - Components uses decorator pattern provided by angular library component "Component". Place the below statements before defining the class in TS file.

@Component({
selector: 'app-archive-data', --> This is selector element which we need to place in HTML file.
templateUrl: './archive-data.component.html', --> HTML template for the data in the selector
styleUrls: ['./archive-data.component.css'],
providers: [NgbModalConfig, NgbModal]
})
Register the component in a module.
 - Add the components in the app module (app.module.ts) inside delcarations array.

@NgModule({
  declarations: [
    AppComponent,
    HeaderComponent,
    FooterComponent,
    ]})

Add HTML mark up.
 - Finally add the selector in the app.component.html

Angular CLI can generate component files automatically using a simple command. Use the below command to generate component files automatically.
 -------------------------------------------------------------[
Use ctrl+~ to open the terminal window in visual studio code |
-------------------------------------------------------------|
Command to generate components: |
|
Use command : ng g c componentName |
g --> Generate |
c --> component |
-------------------------------------------------------------]

Directives:
-------------- 
 There are so many directive angular provides out of the box. Check this API reference for more directives and usage : https://docs.angularjs.org/api

Service: Services are created separately out of components so that components are not tightly coupled with services like calling external HTTP end points.
 Once the service class ts file is created, it should be injected into the components using dependency injection. After creating a service class we need to register the service class in the app module class under providers. See below example:

providers: [
    ViewActiveJobsComponent,
    ArchiverJobConfigurationComponent
  ],

 Dependency Injection: Dependency injection is handled by angular by injecting the dependencies during run time. There will be only one instance of service class per module even though multiple components use the same service class.

 Angular CLI can generate service file automatically using a simple command. Use the below command to generate service files automatically.
 -------------------------------------------------------------[
Use ctrl+~ to open the terminal window in visual studio code |
-------------------------------------------------------------|
Command to generate service: |
|
Use command : ng g s serviceName |
g --> Generate |
s --> service |
-------------------------------------------------------------]


Comments

Popular posts from this blog

Outsystems Tips and Tricks : Adding iFrame in Reactive Web App

In Outsystems Version 11+, there is no iFrame widget available when you are building Reactive Web Applications. So in case you want to add an iFrame HTML tag or for that matter any other HTML element, you could do so by creating a generic web block and pass HTML in to it by doing as follows.

Consuming Workday WSDL into Outsystems

WSDL (Web Service Description Language) is an XML format for describing network services as a set of endpoints operating on messages containing either document-oriented or procedure-oriented information. The operations and messages are described abstractly, and then bound to a concrete network protocol and message format to define an endpoint . Generally consuming a WSDL (Webservice Description Language) in Outsystems is an easy task but it might get trickier when the WSDL has unsupported use cases built into it. This article will help to understand the difficulties associated with such unsupported use case and attempts to provide a solution. Here is the list of unsupported SOAP use cases from Outystems: https://success.outsystems.com/Documentation/11/Extensibility_and_Integration/SOAP/Consuming_SOAP_Web_Services/Unsupporte d_SOAP_Use_Cases#list-attribute-in-a-single-list-attribute Workday WSDL: The following link provides the WWS (Workday Web Services) API Documentation f...

Outsystems Integrations - Connecting to Microsoft Azure Sql Server

In this article, I will show you how to set up your own Microsoft Azure SQL Server Database and then how to integrate this SQL Server database in Outsystems. Create a free Microsoft Azure Account. https://portal.azure.com. Microsoft Azure is a cloud computing service for building, deploying and testing application through Microsoft managed data centers (similar to Amazon’s AWS services) Microsoft provides free accounts with free credit of $200 to spend in the first year of new account. I am using this feature to create a Microsoft Azure SQL Server database in the cloud and will show how easy it is to connect this Azure AQL Server from Outsystems. Click on Add button to add a Azure SQL Database Fill in the details and click on Create button. Your deployment will take few seconds to few min to create. Look for the status in the table. It will change to Created automatically without refreshing the screen and finally when your screen says deployment is compl...