Home QuestionAngular Question Angular JS Interview Question

Angular JS Interview Question

by Dhanik Lal Sahni

1. What is angular?

Angular is a framework for building client applications in HTML and either JavaScript or a language like TypeScript that compiles to JavaScript.

2.What are Decorators in Angular?

Decorators are functions that modify JavaScript classes. Angular has many decorators that attach metadata to classes so that it knows what those classes mean and how they should work.

Example:

    @Injectable()
    export class Product {
      constructor(
        public productService: ProductService) { }
    }

To make Product class injectable in another component, we have marked that as Injectable.

3. How to iterate array or collection in angular?

We can use *ngFor to iterate collection or array in angular. See example in below code, we have collection of products. We have iterate and shown those product name on page.

    export class AppComponent {
        products = ['Soap', 'Rice', 'Sugar', 'Oil'];
    }
   <p>Heroes:</p>
    <ul<p>Heroes:</p>
        <li *ngFor="let p of products">
            {{ p }}
        </li>
    </ul>

4. What is component in angular?

Component decorator allows a class as an Angular component and provide additional metadata that determines how the component should be processed, instantiated and used at runtime.

Components are the most basic building block of an UI in an Angular application. An Angular application is a tree of Angular components. Angular components are a subset of directives. Unlike directives, components always have a template and only one component can be instantiated per an element in a template.

A component must belong to an NgModule in order for it to be usable by another component or application.

     @Component({
      selector: 'product',
      viewProviders: [
        ProviderService
      ],
      template: "<product></product>"
    })

5. How to create envionment files like production and development in Angular CLI?

Following are steps to create enviorment file.

1. create a src/environments/environment.NAME.ts
2. add { “NAME”: ‘src/environments/environment.NAME.ts’ } to the apps[0].environments object in .angular-cli.json
3. use them via the –env=NAME flag on the build/serve commands.

You may also like

Leave a Comment