Angular Environment (1)
Angular Environment (1)
Why Angular?
JavaScript is a powerful programming language that allows developers to use a web
browser as a full application platform. Angular provides a great framework that
makes it faster and easier to create client-side JavaScript applications.
Developers use Angular because it provides a lot of the structure of web
applications—such as data binding, expressions,Pipes,dependency injection, and
HTTP communications
1. Modules
In general, Angular apps use a modular design. While not required, modules are
highly recommended because they allow you to separate your code into separatefiles.
This helps you keep your code files short and manageable while still allowing you to
access the functionality from each one.
We use modules using TypeScript language(.ts file), with Angular you import
external
modules at the top of a file and export the functionality you need at the bottom.
2. Directives
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:
1. Components: A component directive is a directive that incorporates an HTML
template with JavaScript functionality to create a self-contained UI element that can
be added to an Angular application as a custom HTML element. Components are
likely to be the directives you use the most in Angular.
2. Structural: You use structural directives when you need to manipulate theDOM.
Structural directives allow you to create and destroy elements and components from a
view.
3. Attribute: An attribute directive changes the appearance and behavior of HTML
elements by using HTML attributes.
3. Data Binding
One of the best features of Angular is the built-in data binding—the process of
linking data from a component with what is displayed in a web page.
Angular provides a very clean interface to link model data to elements in a web page.
When data is changed on a web page, the model is updated, and when data is
changed in the model, the web page is automatically updated.
This way, the model is always the only source for data represented to the user, and the
view is just a projection of the model.
4. Dependency Injection
Dependency injection is a process in which a component defines dependencies on
other components. When the code is initialized, the dependent component is made
available for access within the component.
Angular applications make heavy use of dependency injection.A common use for
dependency injection is consuming services.
For example, if you are defining a component that requires access to a web server via
HTTP requests, you can inject the HTTP services into the component, and the
functionality is
5. Services
Services are the major workhorses in the Angular environment. Services are singleton
classes that provide functionality for a web app.
For example, a common task of web applications is to perform AJAX requests to a
web server. Angular provides an HTTP service that houses all the functionality to
access a web server.The service functionality is completely independent of context or
state, so it can beeasily consumed from the components of an application.
Angular provides a lot ofbuilt-in service components for basic uses, such as HTTP
requests, logging, parsing,and animation. You can also create your own services and
reuse them throughout
your code. available in the component code
Angular Implementation:
To implement Angular in the appropriate manner.
The following are a few rules to follow when implementing Angular:
o The view acts as the official presentation structure for the application. Indicate any
presentation logic as directives in the HTML template of the view.
o If you need to perform any DOM manipulation, do it in a built-in or custom directive
JavaScript code—and nowhere else.
o Implement any reusable tasks as services and add them to your modules by using
dependency injection.
o Ensure that the metadata reflects the current state of the model and is the single source
for data consumed by the view.
o Define controllers within the module namespace and not globally to ensure that your
application can be packaged easily and avoid overwhelming the globalnamespace.
This may take a few minutes to install. You can now create a new Angular application
by typing:
ng new my-app
my-app is the name of the folder for your application. The ng new command
prompts you with options for the generated application. Accept the defaults by
pressing the Enter key. This may take a few minutes to create the Angular
application in TypeScript and install its dependencies.
Let's quickly run our Angular application by navigating to the new folder and
typing ng serve to start the web server and open the application in a browser:
cd my-app
ng serve
@Component({
selector:'app-root',
templateUrl:'./app.component.html',
styleUrls: ['./app.component.css']
})
exportclassAppComponent {
To get the current execution policy in PowerShell, you can use the
command Get-ExecutionPolicy:
Get-ExecutionPolicy: Gets the current execution policy for the computer
Get-ExecutionPolicy -List: Gets all execution policies for the current
session, listed in precedence order
Get-ExecutionPolicy -Scope <ExecutionPolicyScope>: Gets the
execution policy set for a particular scope
The effective execution policy is determined by: Execution policies set by
Set-ExecutionPolicy and Group Policy settings.
Here are some examples of using Get-ExecutionPolicy:
Get the current execution policy: PS C:\> Get-ExecutionPolicy Restricted
@NgModule({
declarations: [
AppComponent,
ComponentRvrComponent,
LogoComponentComponent,
],
imports: [
BrowserModule,
AppRoutingModule,
FormsModule
],
providers: [
provideClientHydration(withEventReplay())
],
bootstrap: [AppComponent]
})
export class AppModule { }
First, you import NgModule, BrowserModule, and any custom
components, directives, services, and so on that your app has. Second, you
configure the @NgModule object to bootstrap everything together. Notice
that when the component is imported, the bootstrap property has the
component’s export class name. Finally, you export the class named
AppModule.