Computer Knowledge
GUI and Web Frameworks
1,711 Questions
Graphical user interface and web frameworks involve layout management, directives, and application design across platforms like Android and Angular. These concepts are tested in computer science and IT officer competitive exams. Review these questions to understand UI components and coding standards.
Android layout attributesAngular structural directivesVB.Net web methodsJava Swing componentsSiebel application framework
GUI and Web Frameworks Questions
What is an attribute directive in Angular?
-
A directive that adds or removes DOM elements from the template based on a condition.
-
A directive that modifies the behavior of a DOM element.
-
A directive that listens for events on a DOM element.
-
A directive that binds a component property to a DOM element's property.
B
Correct answer
Explanation
Attribute directives in Angular are directives that can modify the behavior of a DOM element. They are used to add additional functionality to DOM elements.
What is an example of an attribute directive in Angular?
-
ngIf
-
ngFor
-
ngSwitch
-
ngClass
D
Correct answer
Explanation
ngClass is an example of an attribute directive in Angular. It allows you to dynamically add and remove CSS classes to a DOM element based on a condition.
What is the purpose of the *ngFor directive in Angular?
-
To conditionally include or exclude DOM elements from the template.
-
To repeat a block of HTML for a collection of data.
-
To modify the behavior of a DOM element.
-
To listen for events on a DOM element.
B
Correct answer
Explanation
The *ngFor directive in Angular is used to repeat a block of HTML for a collection of data. It allows you to easily iterate over an array or object and display its elements in the template.
What is the syntax for the *ngFor directive in Angular?
-
*ngFor="let item of items"
-
*ngFor="item of items"
-
*ngFor="items"
-
*ngFor="let item in items | async"
A
Correct answer
Explanation
The syntax for the *ngFor directive in Angular is *ngFor="let item of items". It allows you to specify the collection of data to iterate over and the variable to use for each item in the collection.
What is the purpose of the ngSwitch directive in Angular?
-
To conditionally include or exclude DOM elements from the template.
-
To repeat a block of HTML for a collection of data.
-
To modify the behavior of a DOM element.
-
To listen for events on a DOM element.
A
Correct answer
Explanation
The ngSwitch directive in Angular is used to conditionally include or exclude DOM elements from the template based on a value. It allows you to display different content depending on the value of a property.
What is the syntax for the ngSwitch directive in Angular?
-
[ngSwitch]="value"
-
(ngSwitch)="value"
-
*ngSwitch="value"
-
ngSwitch="value"
A
Correct answer
Explanation
The syntax for the ngSwitch directive in Angular is [ngSwitch]="value". It allows you to specify the value to switch on and the different cases to handle.
Which of the following is NOT a common type of user interface (UI) element?
-
Buttons.
-
Menus.
-
Icons.
-
Data analytics.
D
Correct answer
Explanation
Data analytics is not a type of UI element, as it involves analyzing data to understand user behavior and patterns, rather than being a visual element that users interact with.
What is the providedIn property used for in Angular services?
-
To specify the scope of the service (root or component)
-
To define the dependencies required by the service
-
To provide metadata about the service for DI
-
To configure the lifecycle hooks of the service
A
Correct answer
Explanation
The providedIn property in Angular services determines the scope of the service, whether it's available throughout the application (root) or only within a specific component (component).
Which Angular decorator is used to mark a class as a service?
-
@Injectable()
-
@Component()
-
@NgModule()
-
@Directive()
A
Correct answer
Explanation
The @Injectable() decorator in Angular is used to mark a class as a service, indicating that it can be injected into other components, services, or modules.
Which lifecycle hook method is called when an Angular service is destroyed?
-
ngOnInit()
-
ngOnDestroy()
-
ngOnChanges()
-
ngAfterViewInit()
B
Correct answer
Explanation
The ngOnDestroy() lifecycle hook method in Angular is called when a service is destroyed, allowing for cleanup tasks and the release of resources.
What is the purpose of the providers array in Angular modules?
-
To define the services available within the module
-
To specify the components and directives used in the module
-
To configure the routing for the module
-
To provide metadata about the module for DI
A
Correct answer
Explanation
The providers array in Angular modules is used to define the services that are available within that module, allowing for their injection into components and other services.
Which Angular service is used for managing state and data across components?
-
StateService
-
StoreService
-
ReduxService
-
NgRx Store
D
Correct answer
Explanation
NgRx Store is a popular state management library for Angular that provides a centralized store for managing application state and data, enabling consistent and predictable state updates across components.
What is the purpose of the @Optional() decorator in Angular?
-
To specify that a dependency is optional and can be omitted if not provided
-
To mark a service as optional and allow it to be injected without a provider
-
To define the scope of a service (root or component)
-
To provide metadata about a service for DI
A
Correct answer
Explanation
The @Optional() decorator in Angular allows you to specify that a dependency is optional and can be omitted if it is not provided by the DI system, providing flexibility in dependency injection.
What is the providedIn property used for in Angular services?
-
To specify the scope of the service (root or component)
-
To define the dependencies required by the service
-
To provide metadata about the service for DI
-
To configure the lifecycle hooks of the service
A
Correct answer
Explanation
The providedIn property in Angular services determines the scope of the service, whether it's available throughout the application (root) or only within a specific component (component).
What is the purpose of the @SkipSelf() decorator in Angular?
-
To skip the current component and search for the dependency in the parent component
-
To skip the current component and search for the dependency in the child components
-
To skip the current component and search for the dependency in the sibling components
-
To skip the current component and search for the dependency in the root component
A
Correct answer
Explanation
The @SkipSelf() decorator in Angular allows you to skip the current component and search for the dependency in the parent component, enabling you to access dependencies from higher levels in the component hierarchy.