Angular Doc
Angular Doc
Note::--New feature Ang17 :-- module.ts file you don’t get in your app , if you
create Normal way app
But you can get module.ts file , if you may follow this
code of line === ng new test - -no -standalone as follows as next type ‘y’
DATA BINDING::======
constructor(){}
ngOnInit(): void {
Component.html
<p> works!</p>
<br><br>
<p> {{dyName}}</p>
<br><br>
{{5+9}}
<br><br>
{{"welcome" + dyName}}
<br><br>
{{dyName.length}}
<br><br><br>
{{dyName.toUpperCase()}}
<br><br>
{{myMethod()}}
<br><br><br>
My App status is {{appStatus? "Online": "Offline"}}
<p>{{message}}</p>
Component.ts
myStyle1= "15px"
--------------------------------------------------------------------------------
message:string="";
onAddCart(){
onInputClick(event:any){
console.log(event.target.value);
}
msg:string="";
onAddtoCart(event:any){
this.msg=event.target.value + " Added in Cart";
}
}
Component.html
Component.ts
Component.html
<input type="text" value="Trends" [(ngModel)]="uName">
<p>{{uName}}</p>
Basic Angular Interview Questions
1. What is Angular?
Synergy with Popular Code Editors and IDEs: Angular offers code
completion and instant error spotting with popular source code editors
and IDEs.
Testing: Angular lets you carry out frequent unit tests using Karma. The
Protractor allows running scenario tests faster while being stable.
Better User Experience: Allows users to see the view of the application
instantly.
Follows the MVC pattern architecture Learning Angular requires time and effort
Unlike the previous versions of Angular, the 7th major release comes
with the splitting of @angular/core. This is done in order to reduce the
size. Not every module is required by an Angular developer. Therefore,
in Angular 7 each split of the @angular/core will have no more than
418 modules.
Data Binding: Angular uses a two-way data binding process and thus is
a bit complex. Backbone.js doesn’t have any data binding process and
thus has a simplistic API.
Attribute Directives
Component Directives
Structural Directives
The single biggest difference between Angular and jQuery is that while
the former is a JS frontend framework, the latter is a JS library. Despite
this, there are some similarities between the two, such as both features
DOM manipulation and provide support for animation.
19. Could you explain the difference between Angular expressions and
JavaScript expressions?
Conventional HTML elements have some content between the tags. For
instance:
However, doing so won’t work the way it worked for HTML elements. In
order to make it work just like the HTML example mentioned above, we
need to use the ng-content Directive. Moreover, it is helpful in building
reusable components.
Model
View
ViewModel
.
@Component({
selector: 'app-header',
template: `
<li class="nav-item">
</li>
<li class="nav-item">
</li>
</ul>
</nav>
})
class HeaderComponent {
goHome() {
this.router.navigate(['']);
}
goSearch() {
this.router.navigate(['search']);
}
35. What is ViewEncapsulation and how many ways are there to do it
in Angular?
To put it simply, ViewEncapsulation determines whether the styles
defined in a particular component will affect the entire application or
not. Angular supports 3 types of ViewEncapsulation:
Emulated: Styles used in other HTML spread to the component.
Native: Styles used in other HTML don’t spread to the component.
None: Styles defined in a component are visible to all components of
the application.
36. What are Lifecycle hooks in Angular? Explain some life cycle
hooks.
Angular components enter their lifecycle from the time it is created to
the time it is destroyed. Angular hooks provide ways to tap into these
phases and trigger changes at specific phases in a lifecycle.
ngOnChanges(): This method is called whenever one or more input
properties of the component changes. The hook receives a
SimpleChanges object containing the previous and current values of the
property.
ngOnInit(): This hook gets called once, after the ngOnChanges hook.
It initializes the component and sets the input properties of the
component.
ngDoCheck(): It gets called after ngOnChanges and ngOnInit and is used
to detect and act on changes that cannot be detected by Angular.
We can implement our change detection algorithm in this hook.
ngAfterContentInit(): It gets called after the first ngDoCheck hook. This
hook responds after the content gets projected inside the component.
ngAfterContentChecked(): It gets called after ngAfterContentInit and
every subsequent ngDoCheck. It responds after the projected content is
checked.
ngAfterViewInit(): It responds after a component's view, or a child
component's view is initialized.
ngAfterViewChecked(): It gets called after ngAfterViewInit, and it
responds after the component's view, or the child component's view is
checked.
ngOnDestroy(): It gets called just before Angular destroys the
component. This hook can be used to clean up the code and detach
event handlers.
How Do You Prepare for an Angular Interview?
To prepare for an Angular interview, you should be aware of the latest
standards and practices of various aspects of web development
processes. This includes knowing TypeScript, JavaScript, HTML, and the
application of these skills.
You also want to do research on the particular company you are
applying for. This will give you a sense of what they expect, and you can
prepare accordingly.
Don’t forget that actual coding and building is also very important. You
should be ready to demonstrate your knowledge, and that is best
practiced through hands-on work. You can look up Angular coding
questions to help you practice.
Conclusion