Challenge your understanding of core Angular features with this focused quiz. Explore key concepts like components, data binding, services, modules, and directives to strengthen your fundamentals and build robust applications.
Which file is typically required for declaring the template, class, and metadata for a reusable view called a component in an Angular application?
Explanation: The Component TypeScript file defines the logic, template reference, and associated metadata for a component. Model JSON files are used for data but do not create UI views. Index HTML files are entry points and do not declare individual components. Service Java files are unrelated, as services are usually defined in TypeScript for Angular applications.
In Angular, which binding technique allows a parent component to send data to a child component using property binding syntax, such as [item]='data'?
Explanation: Input Binding uses property binding syntax to pass data from parent to child components through decorated input properties. Event Binding is used to handle child-to-parent communication. Interpolation Binding displays values in the template, not sending data. Output Binding refers to emitting events to the parent component, not passing data downward.
Why would you implement a service in Angular to handle logic such as fetching data from an external source?
Explanation: Services are ideal for managing data logic, promoting reusability, and isolating concerns away from the component view. Services do not create UI elements; that is the role of components. They are not intended for static HTML storage or styling, which is typically handled by templates and style sheets.
What is the primary reason for declaring modules in an Angular application, such as with an NgModule decorator?
Explanation: Modules group related functionality, helping organize and structure an application’s building blocks. Handling HTTP requests and user authentication are implemented in services or other constructs, not through modules themselves. Modules do not generate database schemas; that task belongs to backend technologies.
Which built-in structural directive in Angular would you use to display a list of items by repeating an element for each item, such as looping through an array of products?
Explanation: *ngFor is designed to iterate over collections and repeat elements accordingly. *ngIf is used for conditionally including or excluding elements. *ngClass is a directive for dynamic CSS class bindings, and *ngModel is used for two-way data binding, not structural repetitions.