Univ 5 Angular QB & Study Material
Univ 5 Angular QB & Study Material
• Components are likely to be the directives you use the most in Angular.
• Structural:
• You use structural directives when you need to manipulate the DON I.
Structural directives allow you to create and destroy e. Iements an
components from a view. d
• Attribute:
• An attribute directive changes the appearance and behaviour of fITML
elements by using HTML attributes.
2. Write down the important angular CLI commands.
• Template:
• This option allows you to add inline HTML to define look of component.
• This is for when there won't be very much code to add, and it's helpful for
when you don't want extra files.
• Templa t e Url:
• This option allows you to import an external template file rather than inline
HTML.
• This is helpful for separating a large amount of IIIML code out of a
component to help with maintainability.
• Styles:
• This option allows you to add inline to your component.
• Use it when only minor style changes are needed.
• Styles Urls:
• This option allows you to import an array of external CSS style
• You should use this rather than styles when importing external CS
• View Providers:
• This is an array of dependency injection providers.
• It allows you to import and use Angular services that provide application
functionality such as HTTP communications.
4. Brief about the Injecting directives in Angular.
✓ Idea ofAngular dependency injection is to define and dynamically inject a dependency
object into another object, which makes available all the functionality provided by
the dependency object.
• Angular provides dependency injection through the use ofproviders and an
injector service.
• In Angular, to use dependency injection on another directive or component,
you need to add directive's or component's class name to declarations metadata
in @NgModule decorator within module for application, which takes in an
array of directives imported into your application.
5. What are the benefits of Angular Expression bound to data model?
• First, you can use the property names and functions that are defined in the
component inside your expressions.
• Second, because the expressions are bound to the component, when data in
the component changes, so do the expressions.
• For example, say that a component contains the tbllowing values:
name: string='Brad';
score: number=95;
<div *ngIf="person"></div>
ngSwitch This directive displays a template based on the value passed As with
ngIf, if the value does not match the case, the eler is not created.
Here is an example:
<div [ngSwitch] ="timeOfDay">
<span [ngSwitchCase] =" 'morning' ">Morning</span>
<span [ngSwitchCase] =" 'afternoon' ">Afternoon</span>
<span [ngSwitchDefault] =" 'daytime' ">Evening</span>
The ngSwitch directive relies on two other directives to
ngSwitchCase and ngSwitchDefault. These directive are be explained
below.
ngSwitchCase This directive evaluates the value it has stored against the value passed
into ngSwitch and determines whether the HTML template it is
attached to should be created.
ngSwitchDefault This directive creates the HTML template if all the above ngS itchCase
expressions evaluate to false. This ensure that some HTML is
generated no matter what.
1. Static Typing
2. Advanced Features and Tooling
1) Module System: TypeScript uses a module system that helps organize code into
reusable and maintainable units. It supports both CommonJS and ES6 modules.
2) IDE Support: Most popular integrated development environments (IDEs) and
code editors provide excellent support for TypeScript. Features like
autocompletion, type checking, and inline documentation enhance developer
productivity.
class Person {
// Properties firstName:
string; lastName: string;
// Constructor
this.firstName = firstName;
this.lastName = lastName;
}
}
}
❖ Every Angular application has at least one NgModule class, the root module,
which is conventionally named AppModule and resides in a file named
app.module.ts.
1. Property binding: This type of binding allows to pass the interpolated values from
application data to HTML. The interpolated values are specified in
{{ and }} bracket pair. For instance - the student.name is interpolating value.
<p>Name: {{ student.name}}</p>
2. Event binding: Event binding is used to capture events on the user's end on the
app and respond to it in the target environment by updating the application data.
Directives are JavaScript classes with metadata that defines the structure and behavior.
Directives provide the majority of UI functionality for Angular applications.
There are three major types of directives:
a. The view acts as the official presentation structure for the application. Indicate
any presentation logic as directives in the HTML template of the view.
b. If you need to perform any DOM manipulation, do it in a built-in or custom
directive JavaScript code—and nowhere else.
c. Implement any reusable tasks as services and add them to your modules by
using dependency injection.
d. Ensure that the metadata reflects the current state of the model and is the single
source for data consumed by the view.
e. Define controllers within the module namespace and not globally to ensure
that your application can be packaged easily and avoid overwhelming the
global namespace.
19. List some Command Line Interface commands in Angular?
Directive Description
ngModel This directive watches a variable for changes and then updates display
value based on those changes. Consider these examples:
<input [(ngModel) ] = "text"><br>
<hl>{{text}}</h1>
ngForm This directive creates a form group and allows it to track the values and
validation within that form group. By using ngSubmit, you can pass the form
data as an object to the submission event. Here is an example:
<form #formName="ngForm" (ngSubmit) ="onSubmit (fo rmN ame)"> </
<div *ngIf="person"></div>
ngSwitch This directive displays a template based on the value passed As with
ngIf, if the value does not match the case, the eler is not created.
Here is an example:
<div [ngSwitch] ="timeOfDay">
<span [ngSwitchCase] =" 'morning' ">Morning</span>
<span [ngSwitchCase] =" 'afternoon' ">Afternoon</span>
<span [ngSwitchDefault] =" 'daytime' ">Evening</span>
The ngSwitch directive relies on two other directives to
ngSwitchCase and ngSwitchDefault. These directive are be explained
below.
ngSwitchCase This directive evaluates the value it has stored against the value passed
into ngSwitch and determines whether the HTML template it is
attached to should be created.
ngSwitchDefault This directive creates the HTML template if all the above ngS itchCase
expressions evaluate to false. This ensure that some HTML is
generated no matter what.
22. List down the common structural directives is nglg a.nd ng Switch.