Some days ago, I decided to start learning a JS framework in order to gain skills and become more useful at work. I choose Angular for the purpose, and started learning it by building up my "professional" personal website.
In this site, one of the biggest obstacles I could encounter was the extremely "bogging" way of adding new stuff with plain HTML. Thus, after some readings, I made an Angular app that generates an ordered list from a Javascript array of JSON descriptors.
For transparency, I made a snippet being as short as possible, while keeping it functionally identical.
<!DOCTYPE html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<script>
function angularCreateMenu(appInitDivId, linksJSON){
document.getElementById(appInitDivId).attributes["ng-init"].value = "links="+JSON.stringify(linksJSON)
}
var list = [
{ref:"./link1.html", content:"First link of the menu"},
{ref:"./link2.html", content:"Second link of the menu"},
{ref:"./link3.html", content:"Third link of the menu"}
];
</script>
</head>
<body>
<div id="angularContainer" ng-app="" ng-init="">
<ol class="list-group">
<li class="list-group-item" ng-repeat="x in links">
<a href=' {{ x.ref }} '> {{ x.content }} </a>
</li>
</ol>
</div>
</body>
<script> angularCreateMenu("angularContainer", list) </script>
Is it OK this way? That final call after body
is slightly annoying for me, but I can't do anything against it.
Are there maybe any additional point to improve this code?