how do I run a jquery in my TS file?

12 views
Skip to first unread message

Russell Maycock

unread,
Nov 15, 2019, 12:39:25 AM11/15/19
to Angular and AngularJS discussion
Hi, I've got so far with this and seem to be stuck at the final hurdle.

in my angular project, ive installed the jquery (npm)
I've added the jquery files to my angular.json file, in the script section.

I've added some simple code to the HTML file and to the TS file of my component and it work! 

great! so I now have a piece of code here :-

(function(d) {
    var params =
    {
        id: "0000000000000000000000000000,
        d: "0000000000000000000",
        wid: "0000000000",
        cb: (new Date()).getTime()
    };
    var qs = Object.keys(params).reduce(function(ak){ a.push(k + '=' + encodeURIComponent(params[k])); return a},[]).join(String.fromCharCode(38));
    var s = d.createElement('script'); s.type='text/javascript';s.async=true;
    var p = 'https:' == document.location.protocol ? 'https' : 'http';
    s.src = p + "://webite.com/Scripts/widget2.aspx?" + qs;
    d.getElementById("joyce").appendChild(s);
})(document);


So I thought it would be better if I created a file in assets (joyce.js) and added that to the angular.json scripts section as well.
So I could just run it when I want to, however, I have no idea how to call this in my TS file or refer to it in my HTML file


can someone please give me some pointers or the answer would be even better :)
How do I run this function in my TS file and how do I add it so it displays on the html page.


Thanks
Russ
Reply all
Reply to author
Forward
0 new messages