FullStack Cafe Interview Plan
FullStack Cafe Interview Plan
Interview Plan
Angular
Topic: Angular
Answer:
Angular’s route guards are interfaces which can tell the router whether or not it should allow
navigation to a requested route. They make this decision by looking for a true or false return
value from a class which implements the given guard interface.
Source: medium.com
Q2: What are the differences between AngularJS (angular 1.x) and
Angular (Angular 2.x and beyond)? ☆☆
Answer:
Angular and AngularJS is basically a different framework with the same name.
Angular is more ready for the current state of web standards and the future state of the web
(ES6\7, immutiablity, components, shadow DOM, service workers, mobile compatibilty,
modules, typescript and so on and so on... )
Angular killed many main features in AngularJS like - controllers, $scope, directives (replaced
with @component annotations), the module definition, and much more, even simple things like
ng-repeat has not left the same as it was.
Also:
Source: stackoverflow.com
Answer:
Components are the most basic building block of an UI in an Angular application. An Angular
application is a tree of Angular components. Angular components are a subset of directives.
Unlike directives, components always have a template and only one component can be
instantiated per an element in a template.
Source: angular.io
Answer:
The absolute minimal configuration for a @Component in Angular is a template. Both template
properties are set to optional because you have to define either template or templateUrl.
When you don't define them, you will get an exception like this:
A selector property is not required, as you can also use your components in a route.
Source: stackoverflow.com
Answer:
Components control views (html). They also communicate with other components and services
to bring functionality to your app.
Modules consist of one or more components. They do not control any html. Your modules
declare which components can be used by components belonging to other modules, which
classes will be injected by the dependency injector and which component gets bootstrapped.
Modules allow you to manage your components to bring modularity to your app.
Source: stackoverflow.com
Answer:
An Angular module is set of Angular basic building blocks like component, directives, services
etc. An app can have more than one module.
@NgModule({
imports: [ BrowserModule ],
declarations: [ AppComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule { }
Source: stackoverflow.com
The separation of concerns is the main reason why Angular services came into existence. An
Angular service is a stateless object and provides some very useful functions.
Source: dzone.com
Answer:
Just bind to the hidden property
Source: stackoverflow.com
Answer:
A pipe takes in data as input and transforms it to a desired output. You can chain pipes
together in potentially useful combinations. You can write your own custom pipes. Angular
comes with a stock of pipes such as DatePipe, UpperCasePipe, LowerCasePipe,
CurrencyPipe, and PercentPipe.
Consider:
In this page, you'll use pipes to transform a component's birthday property into a human-
friendly date.
Source: angular.io
Answer:
The correct syntax is the following:
<div [innerHTML]="theHtmlString"></div>
Working in 5.2.6
Source: medium.com
Answer:
You can get a handle to the DOM element via ElementRef by injecting it into your component's
constructor:
Answer:
Just bind to the hidden property:
[hidden]="!myVar"
Source: medium.com
Answer:
*ngIf effectively removes its content from the DOM while [hidden] modifies the display
property and only instructs the browser to not show the content but the DOM still contains it.
Source: medium.com
Answer:
Write a component when you want to create a reusable set of DOM elements of UI with custom
behaviour. Write a directive when you want to write reusable behaviour to supplement existing
DOM elements.
Source: medium.com
Details:
@HostBinding('[class.valid]') isValid;
Answer:
@HostBinding lets you set properties on the element or component that hosts the directive.
The code applies the css class valid to whatever is using this directive conditionally based on
the value of isValid.
Source: alligator.io
Q16: How would you protect a component being activated through the
router? ☆☆
Answer:
The Angular router ships with a feature called guards. These provide us with ways to control
the flow of our application. We can stop a user from visitng certain routes, stop a user from
leaving routes, and more. The overall process for protecting Angular routes:
Source: scotch.io
Answer:
Just to name a few:
Improvements in AOT,
allowing the "else" clause in ngIf,
support for TypeScript 2.1
breaking out the animations package
Source: github.com/WebPredict
Answer:
The Angular CLI downloads and install everything you need to test an Angular application with
the Jasmine test framework.
The project you create with the CLI is immediately ready to test. Just run this one CLI
command:
ng test
Source: angular.io
Answer:
Structural directives are used to alter the DOM layout by removing and adding DOM
elements. It is far better in changing the structure of the view. Examples of Structural
directives are NgFor and Nglf.
Source: onlineinterviewquestions.com
Answer:
The routing application should add element to the index.html as the first child in the tag
inorder to indicate how to compose navigation URLs. If app folder is the application root then
you can set the href value as below
<base href="/">
Source: github.com/sudheerj