Skip to content

Commit efc2edb

Browse files
committed
chore: highlighting and formatting
1 parent 30ed2c0 commit efc2edb

File tree

7 files changed

+64
-54
lines changed

7 files changed

+64
-54
lines changed

README.md

+35-32
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
# Angular2-Interview-Questions
22

3-
This file contains a number of Angular 2.0 interview questions that can be used when vetting potential candidates. It is by no means recommended to use every single question here on the same candidate (that would take hours). Choosing a few items from this list should help you vet the intended skills you require.
3+
This file contains a number of Angular 2.0 interview questions that can be used when vetting potential candidates. It is by no means recommended to use every single question here on the same candidate (that would take hours). Choosing a few items from this list should help you vet the intended skills you require.
44

55
A developer is perfectly able to use Angular to build applications without being able to answer all of these questions. Addition to having a source for interview questions, my intention is to encourage interested developers to think about these questions. I regularly teach Angular 2 workshops. Oftentimes I do not get enough questions due to limited exposure working with the framework. These questions are the ones I personally needed to answer, to be able lead a team developing our first Angular 2 production application at Autodesk A360.
66

7-
**Note:** Keep in mind that many of these questions are open-ended and could lead to interesting discussions that tell you more about the person's capabilities than a straight answer would.
7+
**Note:** Keep in mind that many of these questions are open-ended and could lead to interesting discussions that tell you more about the person's capabilities than a straight answer would.
88

99
## Table of Contents
1010

11-
1. [Animations Questions](#animations-questions)
12-
1. [Architecture Questions](#architecture-questions)
13-
1. [API Questions](#api-questions)
14-
1. [Template Questions](#template-questions)
15-
1. [Component Questions](#component-questions)
16-
1. [Component Interaction & State Management Questions](#component-interaction-&-state-management-questions)
17-
1. [Forms Questions](#forms-questions)
18-
1. [General Questions](#general-questions)
19-
1. [Services Questions](#services-questions)
20-
1. [Structural Directives Questions](#structural-directives-questions)
21-
1. [Styling Questions](#styling-questions)
22-
1. [Style Guide Questions](#style-guide-questions)
23-
1. [Testing Questions](#testing-questions)
24-
1. [Performance Questions](#performance-questions)
25-
1. [Coding Questions](#coding-questions)
26-
1. [Fun Questions](#fun-questions)
11+
* [Animations Questions](#animations-questions)
12+
* [Architecture Questions](#architecture-questions)
13+
* [API Questions](#api-questions)
14+
* [Template Questions](#template-questions)
15+
* [Component Questions](#component-questions)
16+
* [Component Interaction & State Management Questions](#component-interaction-&-state-management-questions)
17+
* [Forms Questions](#forms-questions)
18+
* [General Questions](#general-questions)
19+
* [Services Questions](#services-questions)
20+
* [Structural Directives Questions](#structural-directives-questions)
21+
* [Styling Questions](#styling-questions)
22+
* [Style Guide Questions](#style-guide-questions)
23+
* [Testing Questions](#testing-questions)
24+
* [Performance Questions](#performance-questions)
25+
* [Coding Questions](#coding-questions)
26+
* [Fun Questions](#fun-questions)
2727

2828

2929
#### General Questions:
@@ -46,10 +46,10 @@ A developer is perfectly able to use Angular to build applications without being
4646

4747
* What does this line do:
4848

49+
```ts
50+
@HostBinding('[class.valid]') isValid;
4951
```
50-
@HostBinding('[class.valid]') isValid;
5152

52-
```
5353
* Why would you use renderer methods instead of using native element methods?
5454
* What is the point of calling renderer.invokeElementMethod(rendererEl, methodName)?
5555
* How would you control size of an element on resize of the window in a component?
@@ -105,7 +105,8 @@ A developer is perfectly able to use Angular to build applications without being
105105
* How are the services injected to your application?
106106
* How do you unit test a service with a dependency?
107107
* Why is it a bad idea to create a new service in a component like the one below?
108-
```
108+
109+
```ts
109110
let service = new DataService();
110111
```
111112

@@ -128,7 +129,8 @@ let service = new DataService();
128129
* What selector force a style down through the child component tree into all the child component views?
129130
* What does :host-context() pseudo-class selector targets?
130131
* What does the following css do?
131-
```
132+
133+
```css
132134
:host-context(.theme-light) h2 {
133135
background-color: red;
134136
}
@@ -166,15 +168,16 @@ let service = new DataService();
166168
* Do you need a Routing Module? Why/not?
167169
* When does a lazy loaded module is loaded?
168170
* Below link doesn't work. Why? How do I fix it?
169-
```
171+
172+
```html
170173
<div routerLink='product.id'></div>
171174
```
172175

173176
#### Observables/RxJS Questions:
174177

175178
* What is the difference between an observable and a promise?
176179
* What are some of the angular 2 apis that are using observables?
177-
* How would you implement a [brush behavior](https://bl.ocks.org/mbostock/34f08d5e11952a80609169b7917d4172) using rxjs?
180+
* How would you implement a [brush behavior](https://bl.ocks.org/mbostock/34f08d5e11952a80609169b7917d4172) using rxjs?
178181
* How would you implement a color picker with rxjs?
179182
* If you need to respond to two different Observable/Subject with one callback function, how would you do it?(ex: if you need to change the url through route parameters and with prev/next buttons).
180183

@@ -184,28 +187,30 @@ let service = new DataService();
184187
* How would you define a custom type?
185188
* What is the difference between an Interface and a Class?
186189
* First line below gives compile error, second line doesn't. Why?
187-
* What are Discriminated union types?
190+
* What are Discriminated union types?
188191
* How do you define Object of Objects type in typescript?
189192

190-
```
193+
```ts
191194
someService.someMethod(x);
192195
someService['someMethod'](x);
193196
```
194197

195198
#### Security Questions:
196199

197-
200+
...
198201

199202
#### Coding Questions:
200203

201204
* What would these components render?
202205

203-
```
204-
import {Component, ContentChildren, Directive, Input, QueryList} from '@angular/core';
206+
```ts
207+
import { Component, ContentChildren, Directive, Input, QueryList } from '@angular/core';
208+
205209
@Directive({selector: 'pane'})
206210
export class Pane {
207211
@Input() id: string;
208212
}
213+
209214
@Component({
210215
selector: 'tab',
211216
template: `
@@ -216,6 +221,7 @@ export class Tab {
216221
@ContentChildren(Pane) panes: QueryList<Pane>;
217222
get serializedPanes(): string { return this.panes ? this.panes.map(p => p.id).join(', ') : ''; }
218223
}
224+
219225
@Component({
220226
selector: 'example-app',
221227
template: `
@@ -231,10 +237,8 @@ export class ContentChildrenComp {
231237
shouldShow = false;
232238
show() { this.shouldShow = true; }
233239
}
234-
235240
```
236241

237-
238242
#### Fun Questions:
239243

240244
* What's a cool project that you've recently worked on?
@@ -245,7 +249,6 @@ export class ContentChildrenComp {
245249
* What's your favorite feature of Angular 2.0?
246250
* How do you like your coffee?
247251

248-
249252
#### Contributors:
250253
* [Ayşegül Yönet](https://developers.google.com/experts/people/aysegul-yonet)
251254
* [Mohamad Atieh](https://github.com/MohamadAtieh)

animation.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
* How do you transition between two states:
2-
```
3-
animations: [
2+
3+
```ts
4+
animations: [
45
trigger('heroState', [
56
state('inactive', style({
67
backgroundColor: '#eee',
@@ -14,10 +15,11 @@ animations: [
1415
transition('active => inactive', animate('100ms ease-out'))
1516
])
1617
]
17-
```
18+
```
19+
1820
* How do you define a wildcard state?
1921

20-
```
22+
```ts
2123
* => *
2224
* => active
2325
```

api.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
21
* What does this line do:
32

4-
```
5-
@HostBinding('[class.valid]') isValid;
6-
```
3+
```ts
4+
@HostBinding('[class.valid]') isValid;
5+
```
6+
77
Binds a host element property (here, the CSS class valid) to a directive/component property (isValid).
88

99
* What would be a good use for NgZone service?

router.md

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
#### What is the diffrence between RouterModule.forRoot() vs RouterModule.forChild()? Why is it important?
22

3-
* forRoot creates a module that contains all the directives, the given routes, and the router service itself.
4-
* forChild creates a module that contains all the directives and the given routes, but does not include the router service.
5-
It registers the routers and uses the router service created at the root level.
3+
* forRoot creates a module that contains all the directives, the given routes, and the router service itself.
4+
* forChild creates a module that contains all the directives and the given routes, but does not include the router service.
5+
It registers the routers and uses the router service created at the root level.
66
* This is important because location is a mutable global property. Having more than one object manipulating the location is not a good idea.
77

88
#### How does loadChildren property work?
99

10-
```
10+
```ts
1111
const routes: Routes = [
1212
...,
1313
{ path: 'edit', loadChildren: 'app/edit/edit.module#EditModule' },
1414
...
1515
]
1616
```
17+
1718
* In the above example, loadChildren tells the router to fetch the EditModule bundle assigned to it *when* the user visits '/edit' url. (To be more precise, it will ask the module loader to find and load it.)
1819
* Router will get the router configuration from edit module.
1920
* It merges EditModule router configuration with the main application configuration.
2021
* Activate all the needed components.
2122

2223
#### Do you need a Routing Module? Why/not?
23-
Yes if the user was expected to navigate between different URLs. The Routing Module interprets the browser's URL as an instruction to load a specific component and its view. The application has to have its main router configured and bootstraped by passing an array of routes to `RouterModule.forRoot()`, and since this returns a module, it has to be added to the `imports` meta property in the main application module.
24+
Yes if the user was expected to navigate between different URLs. The Routing Module interprets the browser's URL as an instruction to load a specific component and its view. The application has to have its main router configured and bootstraped by passing an array of routes to `RouterModule.forRoot()`, and since this returns a module, it has to be added to the `imports` meta property in the main application module.
2425

2526
The RouterModule:
2627

@@ -37,14 +38,15 @@ Note that lazy-loaded modules should be removed from modules tehy were part of s
3738

3839

3940
#### Below link doesn't work. Why? How do I fix it?
40-
```
41+
42+
```html
4143
<div routerLink='product.id'></div>
4244
```
45+
4346
The routerLink should specify a defined path in the routing configuration and the required path parameter (`product.id`). The code above tries to visit a specific product page, so it should be done using *Link Parameters Array*:
4447

45-
```
48+
```html
4649
<div [routerLink]="['/product', product.id]"></div>
4750
```
4851

4952
The above is correct in the case of having `product/:id` as a path in the application router configuration.
50-

services.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#### What is the use case of services?
22

3-
The main use case of Services is to move duplicated code into a single location, acting like a Singleton. It encourages DRY (Don't Repeat Yourself), which is a principle in Software Engineering, aimed at reducing repitition of information or code in a multi-layered architecture.
3+
The main use case of Services is to move duplicated code into a single location, acting like a Singleton. It encourages DRY (Don't Repeat Yourself), which is a principle in Software Engineering, aimed at reducing repitition of information or code in a multi-layered architecture.
44

55
Services can serve as a method of interaction between an application and a data store. It also can provide communication channels between directives, as well as any other business logic access.
66

@@ -11,13 +11,13 @@ There are two ways to inject a service into your application:
1111
- Per Application: Provides the service at an application level
1212
- Per Component: Provides the service at a component level (and all child components)
1313

14-
Providing a service at an application level or a higher level creates a single instance of that service and shares it with all sub directives. This is useful in the case of sharing properties or state between service holders.
14+
Providing a service at an application level or a higher level creates a single instance of that service and shares it with all sub directives. This is useful in the case of sharing properties or state between service holders.
1515

1616
Providing a service for every different component would create an instance for each of the components with separate resources.
1717

1818
Injecting a service can be done by importing the service and specifying it in the `NgModule`'s metadata array preperty `providers`, and inject it into the directive using it via the constructor. To inject a service into another service, annotate the target service class with `@Injectable`.
1919

20-
```
20+
```ts
2121
//annotation used for services injecting other services
2222
@Injectable()
2323
export class MessageService {
@@ -30,13 +30,15 @@ export class MessageService {
3030
[insert answer]
3131

3232
#### Why is it a bad idea to create a new service in a component like the one below?
33-
```
33+
34+
```ts
3435
let service = new DataService();
3536
```
37+
3638
That's a bad idea for several reasons including:
3739

3840
Our component has to know how to create a DataService. If we ever change the DataService constructor, we'll have to find every place we create the service and fix it. Running around patching code is error prone and adds to the test burden.
3941

4042
We create a new service each time we use new. What if the service should cache data and share that cache with others? We couldn't do that.
4143

42-
We're locking the component into a specific implementation of the DataService. It will be hard to switch implementations for different scenarios. Can we operate offline? Will we need different mocked versions under test? Not easy.
44+
We're locking the component into a specific implementation of the DataService. It will be hard to switch implementations for different scenarios. Can we operate offline? Will we need different mocked versions under test? Not easy.

style.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ We can use the /deep/ selector to force a style down through the child component
1111
It works just like the function form of :host(). It looks for a CSS class in any ancestor of the component host element, all the way up to the document root. It's useful when combined with another selector.
1212

1313
* What does the following css do?
14-
```
14+
15+
```css
1516
:host-context(.theme-light) h2 {
1617
background-color: red;
1718
}
File renamed without changes.

0 commit comments

Comments
 (0)