As I delve into the realm of creating an offer letter, a perplexing challenge arises - how can I seamlessly replace specific placeholders with details of selected candidates without leaning on jquery or JS? No $, no document.getelementbyId. A pure TypeScript approach is what I seek. Here's the intricate scenario at play:
A virtual template list stands ready, harboring clauses alongside their corresponding textual content.
templateList = [{
templateId: 1,
templateName: "Offer",
clauses: [
{
clauseName: "Introduction",
clauseId: 1,
texts: [
{
text: "Greetings <<Name>>, Welcome to the Machine",
textId: 1,
}]
},
{
clauseName: "Address",
clauseId: 2,
texts: [
{
text: "<<Address>>",
textId: 2,
}]
},
{
clauseName: "Date Of Joining",
clauseId: 3,
texts: [
{
text: "We anticipate your arrival on <<DateOfJoining>>",
textId: 3,
}]
},
]
}]
The candidate roster is equally significant:
candidateList = [
{ name: "Simba", address: "Some Random Cave" },
{ name: "Doe John", address: "line 4, binary avenue, Mobo" },
{ name: "B Rabbit", address: "8 mile road, Detroit" },
{ name: "Peter Griffin", address: "Spooner Street" },
{ name: "Speedy Gonzales", address: "401, hole 34, Slyvester Cat Road" },
{ name: "Morty", address: "Time Machine XYZ" },
{ name: "Brock", address: "pokeball 420, Medic center" },
]
An intriguing task ahead - substituting the placeholders enveloped by <<>> within the template text (including the delimiters) with the chosen candidate's name or address from the dynamic list upon clicking.
Let's now shift our gaze to the HTML structures:
<div style="display: block;">
<button (click)="showTemplate()">Show template</button>
</div>
<hr /><br />
<div class="row">
<div class="col-4">
<ul>
<ol *ngFor="let x of candidateList">
<a>{{x.name}}</a><br />
<a><small>{{x.address}}</small></a>
<hr />
</ol>
</ul>
</div>
<div class="col-8">
<div class="templateDiv">
<div *ngFor="let temp of clauseList">
<span><strong class="textTemp">{{temp.clauseName}}</strong></span>
<br/>
<div *ngFor="let x of temp.texts">
<p class="txt">{{x.text}}</p>
</div>
</div>
</div>
</div>
</div>
The notion of dynamic data points infiltrates this narrative quite subtly. Explore a live demo showcasing this synergy via this link.
Your insights and expertise are paramount here!