Pankaj Parkar
Indian | 30 | Ex MVP | Angular GDE
$.ajax({
url: "http://somesite/v1/api/getdata",
dataType: 'json',
success: function (json) {
var myData = json;
$.ajax({
url: 'http://someotherurl.com/v1/api/getdata',
success: function (data) {
console.log(data)
}
})
}
});
$.ajax({
url: "http://somesite/v1/api/getdata",
async: false, // to stop util this call receives data
dataType: 'json',
success: function (json) {
var myData = json;
$.ajax({
async: false,
url: 'http://someotherurl.com/v1/api/getdata',
success: function (data) {
console.log(data)
}
})
}
});
function printAll(){
printString("A")
.then(() => printString("B"))
.then(() => printString("C"))
}
async function printAll(){
await printString("A")
await printString("B")
await printString("C")
}
Mechanism to analyse the changes and reflect them on the view "
//network Call
getDataFromServer()
.then(()=> {
//state has changed
detectChanges();
})
//timeout function
setTimeout(()=> {
//Call change detection
detectChanges();
}, 5000)
element.addEventListner('click', (event) =>{
//state could have change
detectChanges();
});
let detectChanges => () => {
if(currentState != prevState)
updateView(currentState);
}
Detect Changes Method
let originalSend = XMLHttpRequest.prototype.send;
XMLHttpRequest.prototype.send = (data) => {
//monkey patch code
if ( URL DOES NOT POINT TO AD SERVER ) {
return originalSend.apply(this, arguments);
}
return false;
};
Zone.afterInvoke()
appliction_ref.ts
appliction_ref.ts
Source: https://github.com/angular/angular/blob/master/packages/core/src/application_ref.ts#L513-L532
There are three change detection strategy.
Change detection fires
CD -> Change Detection
@Input() name1
@Input() name2
[name]="name2"
[name]="name1"
name1 = 'Ravi'
name2 = 'Pankaj'
name1 = 'Ravi'
name2 = 'Keerti'
constructor(
private cd: ChangeDetectorRef
) {
cd.detatch();
}
Forms API made form validation super easy in Angular
Two Types of Form
Template Driven
Model driven
When to use what?
https://addyosmani.com/blog/faster-javascript-memoization/
http://jamesknelson.com/5-types-react-application-state/
https://www.youtube.com/watch?v=esDKcn_1aic
https://github.com/mgechev/angular-performance-checklist
By Pankaj Parkar
Advanced Angular concept