Having difficulty importing external jQuery files from a Content Delivery Network (CDN

Encountering an issue while attempting to utilize external jQuery files from a CDN. Typically, jQuery files should be included at the top alongside other custom jQuery files.

Despite arranging the files in the angular.json file, I continue to face an error that persists regardless of how I adjust the order.

Displayed below are images of my setup and the accompanying error message.

Error in Angular due to importing external custom jQuery files from a CDN []

Arrangement in my angular.json file to prioritize jQuery at the top

   "styles": [
              "src/styles.css",
              "node_modules/bootstrap/dist/css/bootstrap.min.css",              
              "src/assets/css/customcss.css"

            ],
            "scripts": [ 
            "./node_modules/jquery/dist/jquery.js",
            "./node_modules/jquery/dist/jquery.min.js",
            "./node_modules/jquery/dist/jquery.slim.min.js",
            "./node_modules/popper.js/dist/umd/popper.min.js",  
            "./node_modules/bootstrap/dist/js/bootstrap.min.js",
            "src/assets/js/custom.js"

               ]

Incorporating the external custom jQuery library into my Angular index.html page

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title> My site </title>
  <base href="/">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
   <!-- custom css -->
   <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/malihu-custom-scrollbar-plugin/3.1.5/jquery.mCustomScrollbar.min.css">
    </head>

<body>

<!-- jQuery Custom Scroller CDN -->

<script src="https://cdnjs.cloudflare.com/ajax/libs/malihu-custom-scrollbar-plugin/3.1.5/jquery.mCustomScrollbar.concat.min.js"></script>

 <app-root></app-root>
</body>
</html>

Answer №1

To implement this feature, modify the angular.json file

"scripts": [
            "node_modules/jquery/dist/jquery.js",
            "node_modules/bootstrap/dist/js/bootstrap.js",
            "node_modules/datatables/media/js/jquery.dataTables.js",

Avoid inserting script tags into the index.html file

Utilize the setting in the component's TypeScript file

declare const $: any;

ngOnInit() {
   $('#example').DataTable();
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ways to eliminate the dotted line from the image map in Internet Explorer 11

Below you will find the code I am working with: <img alt="Testing 2015" border="0" src="images/Test-2015.jpg" usemap="#Map" /> <p><map name="Map"><area coords="790,100,653,135" href="http://www.google.com/" shape="rect" style="cursor ...

Tips for linking node objects to node identifiers in a d3 tutorial?

Currently, I'm going through a tutorial that can be found at- However, there's a particular section in the tutorial that has me puzzled. "In conclusion, we link node ids to node objects and then substitute the source and target values in our li ...

What is the best way to display a collection of markers imported from a JSON file?

I am currently utilizing the react-native-maps package created by airbnb. You can find the link here: https://github.com/airbnb/react-native-maps However, I am facing an issue when attempting to showcase a list of markers on my map. I have created a test ...

Concealing navigation options using CSS styling

A unique program I developed generates a tree structure that looks like this: <li class="linamesystem">Alternator</li> <ul class="boxfornamegroupsparts"> <li class="linamegroup"><a href="#top(1)">Alternator2</a> ...

What is the best way to modify the color of the active tab I have chosen?

I've designed a tab menu using Divs and CSS, but I'm facing an issue with changing the color of the selected tab. I tried adjusting the background color of the .tab class, but it seems to only work for part of the tab... You can view the problem ...

Contrasting behavior shifts between in-line style declaration and class usage

My goal is to create a grid of boxes, each containing information about different dog breeds. However, I've encountered an issue with styling that has left me puzzled. When I apply a style in-line versus using the same style within a class, the behavi ...

Develop a monitor for an entity that has not been created

Currently, I am tackling a feature that involves tracking an asynchronous request within a synchronous one. Let me elaborate. The code snippet I am working with looks something like this: const myObj = {}; function sendMessage(requestId, data) { kafkaP ...

Ways to make a div grow to occupy the leftover width without resorting to the overflow: hidden technique

<div id="container" style="width:100%;"> <div id="left1" style="float:left; width:100px;">float left</div> <div id="left2" style="float:left; width:100px;">float left</div> <div id="remaining">Remaining width&l ...

What causes the red square to descend when text is added?

Curious fact: when the text "WHY?" is added to the first div, the red square drops down and aligns below the blue square. However, if "WHY?" is absent, the two squares remain side by side. Why does this happen? A common question for beginners learning abou ...

How can I globally assign a JavaScript variable based on an AJAX response?

Here is the ajax code I have: <script> $('a[data-id]').click(function () { var id = $(this).attr('data-id'); var domain = $(this).attr('data-domain'); $.ajax({ url: 'getdata& ...

Tips on invoking the kendo ui datasource read function from a Grid in React.js

I'm currently working with a Kendo UI Grid instance that is connected to a RESTful web service through an inline DataSource. To prevent the data from being pulled when the page loads, I have configured the "autoBind": false property of the Grid. Now ...

The CSS styling for changing the color of a button in React JS is not

Creating a custom css style in mypagestyle.styl with the following properties: :local .mybutton border-radius: 1px; padding: 2px; margin: 2px; font-size: 14px; text-align: center; background-color: #4582ec; color: #fff; All styles are being ...

Resolving Jest error in React JS unit tests

While working on a unit test for React code, I encountered an issue with a particular action. For example, suppose I have the following line in testing.js: const images = require.context('../../../media/promotions', true); Here is the unit tes ...

Only horizontal Webkit Scrollbar Buttons visible

My custom webkit scrollbars have been styled using CSS, everything is displaying correctly except for the arrow increment/decrement buttons on the vertical scrollbar. When I removed "horizontal" from the ::-webkit-scrollbar-button line to make both horiz ...

What is the best way to horizontally align three animated progress bars alongside images?

Check out this jsfiddle that shows a vertical alignment of the progress bars. How can I modify it to align them horizontally and centered? https://jsfiddle.net/bLe0jLar/ .wrapper { width: 100px; height: 100px; } .wrapper > #bar, #bar2, #bar3 { ...

Updating the time and date format within an AngularJS application

I am receiving date and time data from the API and would like to adjust the format. The current format is "2016-05-12", "07:17:35". Desired format: 12-May-2016 7:30 PM: <table class="table"> <thead> <tr> <th& ...

Execute a task when every class element contains a value

$("#btn_02").click(function(){ $(".quant").each(function() { var quantity = $(this).html(); alert (quantity); // each value is 0 if (quantity == 0) {return false;} }); $.ajax({ url: "process02.php", succ ...

Steps to include a dynamic CSS class to a hyperlink within WordPress

Is there a way to apply an active CSS class to a link in Wordpress so that the active menu item will display a different color when the link is visited? <ul> <li class=""><a href="/news">News</a></li> <li class="dev ...

Obtaining information from AngularJS callback function in loopback: A comprehensive guide

I am trying to figure out how to retrieve the "good" array from an angular function. Here is the function I have in my Angular code: app.run(function($rootScope,Communications,$http,$filter) { $rootScope.getCommunication = function(object_type ...

Exploring Scope Data Using a Custom AngularJS Directive

We are completely new to the world of AngularJS and are currently facing a challenge in displaying HTML tooltips from a custom directive within Angular. As beginners in this technology, we are struggling to find the right solution for this issue. Initiall ...