Explain AngularJS $routeProvider Service with an Example
The AngularJS $routeProvider service is used to configure different routes (URLs) and associate each route with a particular view and controller. It allows a single-page application to change views without loading a completely new page.
$routeProvider.when('/home', {
templateUrl: 'home.html',
controller: 'HomeController'
});
Here, /home displays home.html and uses HomeController.
Explain ngStyle Directive
ngStyle is an Angular attribute directive used to change CSS styles dynamically according to component data.
colorValue = "blue";
<p [ngStyle]="{'color': colorValue}">
Hello Students
</p>
Here, the text color is changed dynamically using the value of colorValue.
Explain Custom Directives
A custom directive is a directive created by the developer to add custom behavior or styling to an HTML element. It can be generated using the Angular CLI.
Commandng generate directive highlight
or
ng g directive highlight
Angular creates a directive file such as highlight.directive.ts.
Explain Custom Pipes
A custom pipe is a user-defined Angular pipe created to perform a custom transformation or formatting of data before displaying it in HTML. It can be created using:
ng generate pipe greeting
or
ng g pipe greeting
Explain Observables with RxJS
An Observable is used in Angular to handle asynchronous data and data that arrives over time. Angular uses RxJS (Reactive Extensions for JavaScript) to work with Observables. A component subscribes to an Observable to receive its values.
Exampledata.subscribe(value => {
console.log(value);
});
Here, subscribe() means that the component wants to receive the data emitted by the Observable.