You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+35-32
Original file line number
Diff line number
Diff line change
@@ -1,29 +1,29 @@
1
1
# Angular2-Interview-Questions
2
2
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.
4
4
5
5
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.
6
6
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.
@@ -46,10 +46,10 @@ A developer is perfectly able to use Angular to build applications without being
46
46
47
47
* What does this line do:
48
48
49
+
```ts
50
+
@HostBinding('[class.valid]') isValid;
49
51
```
50
-
@HostBinding('[class.valid]') isValid;
51
52
52
-
```
53
53
* Why would you use renderer methods instead of using native element methods?
54
54
* What is the point of calling renderer.invokeElementMethod(rendererEl, methodName)?
55
55
* 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
105
105
* How are the services injected to your application?
106
106
* How do you unit test a service with a dependency?
107
107
* Why is it a bad idea to create a new service in a component like the one below?
108
-
```
108
+
109
+
```ts
109
110
let service =newDataService();
110
111
```
111
112
@@ -128,7 +129,8 @@ let service = new DataService();
128
129
* What selector force a style down through the child component tree into all the child component views?
129
130
* What does :host-context() pseudo-class selector targets?
130
131
* What does the following css do?
131
-
```
132
+
133
+
```css
132
134
:host-context(.theme-light) h2 {
133
135
background-color: red;
134
136
}
@@ -166,15 +168,16 @@ let service = new DataService();
166
168
* Do you need a Routing Module? Why/not?
167
169
* When does a lazy loaded module is loaded?
168
170
* Below link doesn't work. Why? How do I fix it?
169
-
```
171
+
172
+
```html
170
173
<divrouterLink='product.id'></div>
171
174
```
172
175
173
176
#### Observables/RxJS Questions:
174
177
175
178
* What is the difference between an observable and a promise?
176
179
* 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?
178
181
* How would you implement a color picker with rxjs?
179
182
* 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).
180
183
@@ -184,28 +187,30 @@ let service = new DataService();
184
187
* How would you define a custom type?
185
188
* What is the difference between an Interface and a Class?
186
189
* First line below gives compile error, second line doesn't. Why?
187
-
* What are Discriminated union types?
190
+
* What are Discriminated union types?
188
191
* How do you define Object of Objects type in typescript?
189
192
190
-
```
193
+
```ts
191
194
someService.someMethod(x);
192
195
someService['someMethod'](x);
193
196
```
194
197
195
198
#### Security Questions:
196
199
197
-
200
+
...
198
201
199
202
#### Coding Questions:
200
203
201
204
* What would these components render?
202
205
203
-
```
204
-
import {Component, ContentChildren, Directive, Input, QueryList} from '@angular/core';
* 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.)
18
19
* Router will get the router configuration from edit module.
19
20
* It merges EditModule router configuration with the main application configuration.
20
21
* Activate all the needed components.
21
22
22
23
#### 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.
24
25
25
26
The RouterModule:
26
27
@@ -37,14 +38,15 @@ Note that lazy-loaded modules should be removed from modules tehy were part of s
37
38
38
39
39
40
#### Below link doesn't work. Why? How do I fix it?
40
-
```
41
+
42
+
```html
41
43
<divrouterLink='product.id'></div>
42
44
```
45
+
43
46
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*:
Copy file name to clipboardExpand all lines: services.md
+7-5
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
#### What is the use case of services?
2
2
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.
4
4
5
5
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.
6
6
@@ -11,13 +11,13 @@ There are two ways to inject a service into your application:
11
11
- Per Application: Provides the service at an application level
12
12
- Per Component: Provides the service at a component level (and all child components)
13
13
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.
15
15
16
16
Providing a service for every different component would create an instance for each of the components with separate resources.
17
17
18
18
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`.
19
19
20
-
```
20
+
```ts
21
21
//annotation used for services injecting other services
22
22
@Injectable()
23
23
exportclassMessageService {
@@ -30,13 +30,15 @@ export class MessageService {
30
30
[insert answer]
31
31
32
32
#### Why is it a bad idea to create a new service in a component like the one below?
33
-
```
33
+
34
+
```ts
34
35
let service =newDataService();
35
36
```
37
+
36
38
That's a bad idea for several reasons including:
37
39
38
40
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.
39
41
40
42
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.
41
43
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.
Copy file name to clipboardExpand all lines: style.md
+2-1
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,8 @@ We can use the /deep/ selector to force a style down through the child component
11
11
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.
0 commit comments