1603420624
In this article, we will go through some of the angular features by explaining some of its core API. You can follow this angular cheat sheet and use in your project.
Angular gives us the ability to do a whole lot using their CLI. You can config the entire application by just using the CLI. Here are some of the commands:
npm install -g @angular/cli
: This command will install the Angular CLI into our local machine using npm.ng new <application name>
: This will setup a new Angular application using the ng new
command.ng new <application name> --prefix best
: This create a new project and set the projects prefix to new.ng new --help
: This returns all available Angular command list.ng lint my-app
: This command checks our entire application for any linting warnings.ng lint my-app --fix
: If there are any form of linting errors, this command will fix it.ng lint my-app --format stylish
: This formats our entire codebase.ng lint my-app --help
: This command returns all the available linting command list.ng add <package name>
: This command will use your package manager to download new dependencies and update the project with configuration changes.ng generate component <name>
: This will create a new component on our application. We can also use the ng g c <name>
shorthand to do this.ng g d <directive name>
: This command angular directive.ng g s <service name>
: Creates a new Javascript class based service.ng g p <pipe name>
: Generates a new pipeng g cl <destination>
: This will create a new class in the specified directory.ng build
: Builds the application for production and stores it in the dist
directory.ng serve -o
: Serves the application by opening up the application in a browser using any port 4200 or any available port.ng serve -ssl
: serves the application using sslA component in Angular has a life-cycle, a number of different phases it goes through from birth to death.We can hook into those different phases to get some pretty fine grained control of our application.Here are some of the hooks:
ngOnChanges
: This is called whenever one of input properties change.ngOnInit
: This is called immediately after ngOnChanges
is completed and it is called once.ngOnDestroy
: Called before angular destroys a directory or componentngDoCheck
: Whenever a change detection is ran, this is called.ngAfterContentInit
: Invoked after Angular performs any content projection into the component’s view.ngAfterContentChecked
:This is called each time the content of the given component has been checked by the change detection mechanism of Angular.ngAfterViewInit
This is called when the component’s view has been fully initialized.ngAfterViewChecked
: Invoked each time the view of the given component has been checked by the change detection mechanism of Angular.Always remember that hooks working in a component or directory, so use them in our component, we can do this:
`class ComponentName {
@Input('data') data: Data;
constructor() {
console.log(`new - data is ${this.data}`);
}
ngOnChanges() {
console.log(`ngOnChanges - data is ${this.data}`);
}
ngOnInit() {
console.log(`ngOnInit - data is ${this.data}`);
}
ngDoCheck() {
console.log("ngDoCheck")
}
ngAfterContentInit() {
console.log("ngAfterContentInit");
}
ngAfterContentChecked() {
console.log("ngAfterContentChecked");
}
ngAfterViewInit() {
console.log("ngAfterViewInit");
}
ngAfterViewChecked() {
console.log("ngAfterViewChecked");
}
ngOnDestroy() {
console.log("ngOnDestroy");
}
}
Angular comes with its DOM features where you can do a whole lot from binding of data and defining of dynamic styles. Let’s take a look at some features: Before we dive into the features, a simple component.ts file is in this manner:
import { Component } from '@angular/core';
@Component({
// component attributes
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.less']
})
export class AppComponent {
name: 'Angular';
}
Interpolation
: using {{data to be displayed}}
will display dynamic content from the ts file.<button (click)="callMethod()" ... />
: Adding Click events to buttons to call a method defined in the ts file<button *ngIf="loading" ... />
: Adding Conditionals to to elements. Conditionals have to listen to truthy or falsy value.*ngFor="let item of items``"
: iterate throught a defined list of items.Picture this as a for loop.<div [ngClass]="{green: isTrue(), bold: itTrue()}"/>
: Adding dynamic classes based on conditionals.<div [ngStyle]="{'color': isTrue() ? '#bbb' : '#ccc'}"/>
: Adding dynamic styles to template based on conditionsPassing data from one component to another can be a little bit tricky in Angular. You can pass data from child to parent, parent to parent and between two unrelated components:
input()
: This method helps To pass value into child component.export class SampleComponent {
@Input() value: 'Some Data should go in here';
}
Child components are registered in parents component like this:
<child-component [value]="data"></child-component>
output()
: This method Emits event to the parent component. Bunch of data can be passed into emitted event which makes it a medium of passing data from child to parent:To Emit the event from the child component:
@Output() myEvent: EventEmitter < MyModel > = new EventEmitter();
calledEvt(item: MyModel) {
this.myEvent.emit(item);
}
And then the parent component listens to that event:
<parent-component
(myEvent)="callMethod()"></parent-component>
Routing is another cool feature of Angular, with the Angular Routing system we can navigate through pages and even add route guards.
const routes: Routes = [
{ path: 'home', component:HomeComponent },
{ path: 'blog/:id', component: BlogPostCompoent },
{ path: '**', component: PageNotFoundComponent }
];
For routing to work, add this the your angular.module.ts
file:
RouterModule.forRoot(routes)
There are situations where by you want to keep track of what is happening in your routes, you can add this to enable tracking in your angular project:
RouterModule.forRoot(routes,{enableTracking:true})
To navigate through pages in Angular, we can use the routerLink
attribute which takes in the name of the component we are routing to:
<a routerLink="/home" routerLinkActive="active"> Crisis Center</a>
The routerLinkActive="active``"
will add an active class to the link when active.
We can define guard for route authentication. We can use the CanActivate
class to do this:
class AlwaysAuthGuard implements CanActivate {
canActivate() {
return true;
}
}
To use this rote guard in our routes we can define it here:
const routes: Routes = [
{ path: 'home', component:HomeComponent },
{ path: 'blog/:id', component: BlogPostCompoent,canActivate: [AlwaysAuthGuard], },
{ path: '**', component: PageNotFoundComponent }
];
Angular services comes in handy when you can to do things like handling of http request and seeding of data on your application.They focus on presenting data and delegate data access to a service.
@Injectable()
export class MyService {
public users: Users[];
constructor() { }
getAllUsers() {
// some implementation
}
}
To use this service in your component, import it using the import statement and then register it in the constructor
import MyService from '<path>'
constructor(private UserService: MyService)
To make things easier, we can use this command to generate a service in Angular
ng g s <service name>
Angular comes with its own http service for making http request. To use it, you have to first of all import it into your root module:
import { HttpClientModule} from "@angular/common/http";
After importing it, we can now use it inside our service for making of http request:
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
@Injectable({
providedIn: 'root'
})
export class UserService {
constructor(private http: HttpClient) { }
getAllUsers() {
return this.http.get(`${baseURL}admin/list-users`);
}
}
An interceptor is a piece of code that gets activated for every single HTTP request received by your application. Picture an interceptor as a middleware in nodejs where by where http request made is passed through this piece of code.
To define an interceptor create a http-interceptor.ts
file inside your src directory and add this:
import { Injectable } from '@angular/core';
import {
HttpEvent,
HttpInterceptor,
HttpHandler,
HttpRequest,
HttpErrorResponse,
HttpResponse
} from '@angular/common/http';
import { Observable } from 'rxjs';
import { tap } from 'rxjs/operators';
@Injectable({
providedIn: 'root'
})
export class HttpConfigInterceptor implements HttpInterceptor {
constructor() { }
intercept(req: HttpRequest<any>, next: HttpHandler) {
// Get the auth token from localstorage.
const authToken = localStorage.getItem('token');
// Clone the request and replace the original headers with
// cloned headers, updated with the authorization.
const authReq = req.clone({
headers: req.headers.set('Authorization', authToken)
});
// send cloned request with header to the next handler.
return next.handle(authReq);
}
}
This is a simple interceptor which checks if users has token in their device localstorage. If the user does , it will pass the token in all the http headers.
Pipes in Angular gives us the ability to transform data to any specific format. For example you can write a simple pipe that will format an integer to a currency format or format dates to any form. Angular comes with some built in pipes like the date and currency pipe.
We can define our own custom pipes too by doing this:
import { Pipe, PipeTransform } from '@angular/core';@Pipe({ name: 'exponentialStrength' })
export class ExponentialStrengthPipe implements PipeTransform {
transform(value: number, exponent?: number): number {
return Math.pow(value, isNaN(exponent) ? 1 : exponent);
}
}
To use a pipe in our component we can do this:
{{power | exponentialStrength: factor}}
#angular #web-development #javascript #programming #developer
1598940617
Angular is a TypeScript based framework that works in synchronization with HTML, CSS, and JavaScript. To work with angular, domain knowledge of these 3 is required.
In this article, you will get to know about the Angular Environment setup process. After reading this article, you will be able to install, setup, create, and launch your own application in Angular. So let’s start!!!
For Installing Angular on your Machine, there are 2 prerequisites:
First you need to have Node.js installed as Angular require current, active LTS or maintenance LTS version of Node.js
Download and Install Node.js version suitable for your machine’s operating system.
Angular, Angular CLI and Angular applications are dependent on npm packages. By installing Node.js, you have automatically installed the npm Package manager which will be the base for installing angular in your system. To check the presence of npm client and Angular version check of npm client, run this command:
· After executing the command, Angular CLI will get installed within some time. You can check it using the following command
Now as your Angular CLI is installed, you need to create a workspace to work upon your application. Methods for it are:
To create a workspace:
#angular tutorials #angular cli install #angular environment setup #angular version check #download angular #install angular #install angular cli
1593184320
What is Angular? What it does? How we implement it in a project? So, here are some basics of angular to let you learn more about angular.
Angular is a Typescript-based open-source front-end web application platform. The Angular Team at Google and a community of individuals and corporations lead it. Angular lets you extend HTML’s syntax to express your apps’ components clearly. The angular resolves challenges while developing a single page and cross-platform applications. So, here the meaning of the single-page applications in angular is that the index.html file serves the app. And, the index.html file links other files to it.
We build angular applications with basic concepts which are NgModules. It provides a compilation context for components. At the beginning of an angular project, the command-line interface provides a built-in component which is the root component. But, NgModule can add a number of additional components. These can be created through a template or loaded from a router. This is what a compilation context about.
Components are key features in Angular. It controls a patch of the screen called a view. A couple of components that we create on our own helps to build a whole application. In the end, the root component or the app component holds our entire application. The component has its business logic that it does to support the view inside the class. The class interacts with the view through an API of properties and methods. All the components added by us in the application are not linked to the index.html. But, they link to the app.component.html through the selectors. A component can be a component and not only a typescript class by adding a decorator @Component. Then, for further access, a class can import it. The decorator contains some metadata like selector, template, and style. Here’s an example of how a component decorator looks like:
@Component({
selector: 'app-root',
templateUrl: 'app.component.html',
styleUrls: ['app.component.scss']
})
Modules are the package of functionalities of our app. It gives Angular the information about which features does my app has and what feature it uses. It is an empty Typescript class, but we transform it by adding a decorator @NgModule. So, we have four properties that we set up on the object pass to @NgModule. The four properties are declarations, imports, providers, and bootstrap. All the built-in new components add up to the declarations array in @NgModule.
@NgModule({
declarations: [
AppComponent,
],
imports: [
BrowserModule,
HttpClientModule,
AppRoutingModule,
FormsModule
],
bootstrap: [AppComponent]
})
Data Binding is the communication between the Typescript code of the component and the template. So, we have different kinds of data binding given below:
#angular #javascript #tech blogs #user interface (ui) #angular #angular fundamentals #angular tutorial #basics of angular
1624138795
Learn How to use Angular Material Autocomplete Suggestions Search Input. I covered multiple use cases.
Please watch this video. I hope this video would be helpful for you to understand it and use it in your projects
Please subscribe: https://www.youtube.com/channel/UCL5nKCmpReJZZMe9_bYR89w
#angular #angular-material #angular-js #autocomplete #angular-material-autocomplete #angular-tutorial
1625232772
Although Angular JS has bought headlines over the domain of Web application development, its relevance downtime does not offer any guarantee. Since the JavaScript application is the child of Google, its web features may have some value. Angular JS enables the developer to write most of the code in HTML which brings the application together. Such potentiality and simplicity of the program from the Angular Development Company made Angular popular among JavaScripts.
But the real question arises on the integrity and the safety Angular can provide to the industry. Angular regularly updates its libraries to fix security issues over earlier versions. However, the private and customized Angular versions fall back from the latest versions. These versions might lack the crucial security patches. As a piece of advice, developers can share their improvement requests in the community.
Backward compatibility indicates that the updated versions can function with the outdated versions. Hence, it can simplify the migration procedures to the latest Angular version. Some portions of the AngularJS apps need lazy loading to ease the update and to facilitate the transfer of large projects.
Since AngularJS tends to spoil backward compatibility, it might cause future problems in a program.
The Changing Face of Frameworks
There were several ups and downs in the Web application market over the past. A few years ago, SproutCore ruled the throne as a top framework. However, according to Google search trends, BackboneJS later stole the spotlight which again passed over to EmberJS. But, there remains no comparison for AngularJS.
Birthed by Adam Abrons and Misko Hevery, the Brat Tech engineers in 2009, the Angular Development Company AngularJS took a swift transition to open-source. When Misko Hevery joined Google, he continued to develop Angular JS. The platform began to earn its place by December of 2012 according to Google Trends.
In the year 2015, the potential of AngularJS surpassed other frameworks and offered job placements for many developers. However, AngularJS is not entirely without competition as Facebook came up with ReactJS. Hence, there is a race to show which surpasses the other. But, according to Jeff Schroeder, among the native apps, React elevates mobile app development to higher levels.
Continuous Development in Angular JS
AngularJS has high popularity yet, the developers break backward compatibility on a regular basis. Therefore, the supporters of AngularJS have to learn the AngularJS framework again and again. A critic of AngularJS – Danny Tuppeny, points out that the framework is unstable as it offers short-term support. The developers develop the framework every now and then which can puzzle its users. However, a mobile Web developer by the name of Nene Bodonkor indicates another factor. The frameworks become satisfactory and since they fail to keep up with the market requirements, change becomes crucial.
On the contrary, Yehuda Katz, the creator of EmberJS suggests that the fast-paced lifestyle needs to slow down. Therefore, these constant changes can compel people to reduce and balance their pace. Both, ReactJS from Facebook and EmberJS fight to achieve maximum backward compatibility. Such a characteristic helps these frameworks to come to use for an enterprise. But, AngularJS still has its upper hand over its competitors.
The simple-to-learn design of the Angular Framework with various functions
A legacy system includes few characteristics like old technology that are not compatible with the present systems. These systems do not remain available for purchase from distributors or vendors. These legacy systems cannot update nor patch up by themselves as the developer or vendor stops its maintenance.
The CTO of a mobile and Web app development company Monsoon, Michi Kono agreed on the decisions. But he also commented that the core developers at AngularJS miscommunicated the information. As the AngularJS framework has its uses in Google, they can use the platform for legacy versions and supporting enterprises. According to Michi Kono, AngularJS can promise a safe approach for its use in enterprises. The framework of Angular Development Company USA makes learning simple as it lacks strong convention opinions. The framework is easy for developers to learn and Angular has its applications on other parallel technologies. Vast organizations that have a demand for on-scale development and hiring procedures can use the framework to their advantage.
The low level of Angular appears more as a toolbox than a framework. Such an approach makes Angular useful on a wide variety of utility functions. The developer can use the JavaScript framework to add a single website button through a separate framework. Major companies like Google, Facebook and Microsoft aim to improve JavaScript to match entrepreneur requirements. Since AtScript or the typed JavaScript from Google, will form the backbone of AngularJS 2.0, several developers shall prefer to leverage it.
The Best Fit
AngularJS has several promising aspects for developers from different enterprises to try. But the JavaScript framework undergoes several alterations by its developers. Yet, some of the JavaScript frameworks grab the focus of various users for which they remain in maintenance. Therefore, according to Brian Leroux, the Adobe Web developer, there are two options left. Developers can either imprison themselves within vast rewrites with no forward progress. Or Hire angular developers who can focus their attention to optimize the website architecture. Therefore, developers need to stay up-to-date with the current developments in the web application frameworks like AngularJS.
AngularJS frameworks carry lots of potential in real-time markets. But, the developers need to stay up-to-date to tackle the regular changes in its infrastructure.
#hire angular developers #angular #angular web development #angular development company #angular services #angularjs
1624334049
Save up to 60% of development cost and also get state-of-art infrastructure, experienced AngularJS web development team and latest technologies development.
Agile & DevOps Approach for on-time delivery
Strict NDA terms to ensure complete privacy
Flexible engagement models as per your needs
100% money-back guarantee, if not satisfied
Angularjs development company in India
#angular js development company #angular js web development #angular js development company in india #angular development company in india #angular development india #angular development company india