Knockout component with <script> tag not executing after loading with binding

154
July 24, 2019, at 6:10 PM

Similar to

Proper way to execute a script tag in a Knockout HTML template

As I understand things, a <script> tag can go anywhere in the body and will function fine on initial page load and parsing. I am using KO components, and I would like to include a <script> tag inside the component. I'm doing this so that I can link a component with the JS functionality, so they enter and leave the DOM together.

If I run the following, it loads AND executes the content of the <script> tag:

function loadJs(file, hash){
    var fileObj=document.createElement('script');
    fileObj.setAttribute('type','text/javascript');
    fileObj.setAttribute('src', file);
    if (hash != undefined) {
        fileObj.setAttribute('integrity', hash);
    }
    fileObj.setAttribute('crossorigin', 'anonymous')
    document.getElementsByTagName('head')[0].appendChild(fileObj);
}

If I use the KO default loader to load/register the component, the component loads correctly but the content of the script tag does not execute. The component bindings are all working fine it seems:

ko.components.register(name, {
    viewModel: { instance: containerVm },
    template: html
});

Am I missing a "loading" step or something that executes the contents of the component after registering?

Rent Charter Buses Company
READ ALSO
Easy way to expose an api end point to run linux command on a server protected by jump server access

Easy way to expose an api end point to run linux command on a server protected by jump server access

We need to have a simple API which accepts a date time as parameter and makes the change on the server

158
Logback default value delimiter not working

Logback default value delimiter not working

I am using Logback to configure my logging pattern for a logger that I use in an AWS Lambda Function

163
Get rest-assured request specifications as string

Get rest-assured request specifications as string

I am trying to get all request details (request url, proxy, header, body etc) as a string since I need to redirect this to a logback log fileI have declared a common base class where I have declared the request variable (io

205
Why are RecyclerView rows being populated with same data?

Why are RecyclerView rows being populated with same data?

I'm trying to populate a RecyclerView using data stored in a ArrayListWhen the RecyclerView loads each piece of data is repeted 4x in each row

182