Module in Angular:
Modules are logical boundaries in your application and the application is divided into separate modules to separate the functionality of your application. Let's take an example of app.module.ts root module declared with @NgModule decorator as below,
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
@NgModule ({
imports: [ BrowserModule ],
declarations: [ AppComponent ],
bootstrap: [ AppComponent ],
providers: []
})
export class AppModule { }
The NgModule decorator has five important(among all) options
The imports option is used to import other dependent modules. The BrowserModule is required by default for any web-based angular application
The declarations option is used to define components in the respective module
The bootstrap option tells Angular which Component to bootstrap in the application
The providers option is used to configure set of injectable objects that are available in the injector of this module.
The entryComponents option is a set of components dynamically loaded into the view.
What are decorators in angular?
A class decorator is a decorator that appears immediately before a class definition, which declares the class to be of the given type and provides metadata suitable to the type
A Decorator is a special kind of declaration that can be attached to a class declaration, method, accessor, property, or parameter. Decorators use the form @expression, where the expression must evaluate to a function that will be called at runtime with information about the decorated declaration.
The following list of decorators comes under class decorators,
@Component()
@Directive()
@Pipe()
@Injectable()
@NgModule()
If we say in simple term selector is name which is used in our view like html tag. as we all know angular2 is component based. so selector is just provide the name of the component which is being called by its className in the directives list and called by selector name in the view of the another component like this:-
If we say in simple term selector is name which is used in our view like html tag. as we all know angular2 is component based. so selector is just provide the name of the component which is being called by its className in the directives list and called by selector name in the view of the another component like this:-
What happens in aot?
Below are the list of AOT benefits,
- Faster rendering: The browser downloads a pre-compiled version of the application. So it can render the application immediately without compiling the app.
- Fewer asynchronous requests: It inlines external HTML templates and CSS style sheets within the application javascript which eliminates separate ajax requests.
- Smaller Angular framework download size: Browser doesn't require downloading the Angular compiler. Hence it dramatically reduces the application payload.
- Detect template errors earlier: Detects and reports template binding errors during the build step itself
- Better security: It compiles HTML templates and components into JavaScript. So there won't be any injection attacks
Commonds:
1)Generate new component:
ng g c componentname->componentname-component.ts
ng g p trans-> trans-pipe.ts
Comments
Post a Comment