Alasql into HTML not updating Angular-based page
See original GitHub issueWorking in Angular flavour Ionic (5.4.16)
Running the INTO HTML(cssSelector,options) command has no visible result and throws no error.
I’ve confirmed that the code is continuing to run after this line.
I feel like just dumping the contents of the html and ts files in here would be unhelpful but here’s a direct copy-paste of relevant lines.
HTML file
<div id="res"></div>
**ts file **
res = alasql(queryToRun)
console.log(res)
if (res.length < 1){
// Looks like the user didn't get any results back
myError = "Looks like your query didn't return any results \n\n"
if (queryToRun.toLowerCase().includes("where")){
myError = myError+"Double check your 'where' statement to make sure the columns are right. \nAnd if you're searching for text you're putting that text in 'quotes' "
}
throw myError
}
console.log("Writing to html")
res2 = alasql(`SELECT * INTO HTML("#res", { headers :true }) FROM ?`, [res])
console.log(res2)
I’m not terribly experienced with Angular but have seen that it rejects attempts to update element contents directly. For example, in the same ts file I have to write the below to clear the contents from the div I want alasql to put this table into. If I don’t first
var output = document.querySelector('#res') as HTMLInputElement | null;
output.innerText = ''
I think alasql is updating html elements using el.innerHTML+=s
which could be the problem.
A quick(er) solution than adding a specific workaround for this could be to give the option of returning html rather than json (sorry if I’ve missed that as an existing feature already).
Issue Analytics
- State:
- Created a year ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
Understood! Good to confirm and thanks for the pointer! Constructing the output myself was my next port-of-call but given how much thought you’ve put in to a bunch of this stuff it seemed silly not to try to use the logic you’ve already laid out.
I’ll probably make something Angular-native. Anywhere helpful to share it if I do?
Share it here - then we get it into the wiki if it seems to be of general interest