I wanted to find the answer to: In Angular routing when a link is clicked and the routing url generated, is the entire html page reloaded, or just a portion of the page?
Using the Angular basic tutorial, 'Tour of Heroes', I put a statement to draw a box in a different color (code from here and here), in every component's html template. For instance...
<h1>{{title}}</h1>
<nav>
<a routerLink="/dashboard">Dashboard</a>
<a routerLink="/heroes">Heroes</a>
</nav>
<div style="width:100px;height:100px;border:1px solid rgb(255, 255, 0);">This is app component!</div>
<router-outlet></router-outlet>
<app-messages></app-messages>
But I cannot tell whether only the panel was redrawn and not the entire page.
To test this, I thought of drawing the rectangle in a random color each time. The point of creating a random colored shape is to distinguish if the rectangles change color (entire page was reloaded) or whether only color of rectangle in component changes (then only component was reloaded).
Following the articles here and here
I created a src/custom.js file and in it put
(function random_rgba() {
var o = Math.round, r = Math.random, s = 255;
// return 'rgba(' + o(r()*s) + ',' + o(r()*s) + ',' + o(r()*s) + ',' + r().toFixed(1) + ')';
document.write("<div style=\"width:100px;height:100px;border:1px solid " + " rgb(0, 255, 0);" + ">This is a hero detail component!</div>");
})()
and in angular.json,
"scripts": [
"src/custom.js"
]
But in hero-detail.component.html
<div><script>random_rgba();</script></div>
No colored rectangles are drawn when I reload the page. :(