Angular MCQs – Angular Project Structure and Fundamentals

21.) How can you install a third-party package in an Angular project?

A) ng add package-name
B) npm install package-name
C) Both A and B
D) ng install package-name

Answer: Option C

Explanation: You can install third-party packages using npm install package-name or ng add package-name (if the package supports Angular CLI integration).

22.) How can you create a new Angular service using CLI?

A) ng generate service service-name
B) ng create service service-name
C) ng add service service-name
D) ng new service-name

Answer: Option A

Explanation: The ng generate service command creates a new service file and its corresponding spec file.

23.) What is the purpose of polyfills.ts in an Angular project?

A) It provides compatibility with older browsers
B) It handles Angular animations
C) It defines API endpoints
D) It is used for database connectivity

Answer: Option A

Explanation: The polyfills.ts file ensures Angular apps run smoothly on older browsers by including necessary JavaScript polyfills.

24.) What is the default command to open an Angular project in a browser after serving?

A) npm start
B) ng open
C) ng serve –open
D) ng start

Answer: Option C

Explanation: The ng serve –open command starts the Angular development server and automatically opens the app in a browser.

25.) What is the main purpose of an Angular module?

A) To define global CSS styles
B) To group related components, directives, and services
C) To store API response data
D) To manage component lifecycles

Answer: Option B

Explanation: Angular modules (@NgModule) organize the app by grouping related components and services.

Leave a Reply

Your email address will not be published. Required fields are marked *