Ok, so as my requirement is to get this string value an API, and so on, I don't know what it will be... I've put in place a simple parser, that I will update when new needs come in.
For those who might be interested in, here is the function for the following html : var test = "<h1>test - {{Contact.FirstName}}</h1>";
:
public retrieveValue(from: string) {
var tmp = from.split("{{");
for (var i = 0; i < tmp.length; i++) {
var val = tmp[i].split("}}")[0];
var toReplace = "{{" + val + "}}";
var tmp1 = val.split(".");
var final: any | string = this;
for (var j = 0; j < tmp1.length; j++)
final = final[tmp1[j]];
var re = new RegExp(toReplace,"g");
from = from.replace(re, final);
}
return from;
}
this function doesn't work (yet) for array, but it can be extended pretty easily I think.
If this answer has at least 10 "useful" votes, I will mark it as the answer. otherwise Günter Zöchbauer's answer will be the one :)
Thanks for your help guys.
test - "+variable[0]+"
";` – bergben Feb 15 '17 at 16:27