javascript - Using script tag in Angular 6 component.html - Stack Overflow

I'm aware that Angular removes the script tags in the ponent.html files, but from all the differen

I'm aware that Angular removes the script tags in the ponent.html files, but from all the different forums I've checked out, I haven't found one to successfully solve my problem. I'm trying to put this code into my ontologyponent.html file

<script>
  var widget_tree = $("#widget_tree").NCBOTree({
     apikey: "<my-api-key>",
     ontology: "ENVO"
  });
</script>

My index.html already has the necessary scripts as well

<link rel="stylesheet" type="text/css" href="../src/widgets/jquery.ncbo.tree.css">
<script src="//ajax.googleapis/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="../src/widgets/jquery.ncbo.tree-2.0.2.js"></script>

I'm aware that Angular removes the script tags in the ponent.html files, but from all the different forums I've checked out, I haven't found one to successfully solve my problem. I'm trying to put this code into my ontology.ponent.html file

<script>
  var widget_tree = $("#widget_tree").NCBOTree({
     apikey: "<my-api-key>",
     ontology: "ENVO"
  });
</script>

My index.html already has the necessary scripts as well

<link rel="stylesheet" type="text/css" href="../src/widgets/jquery.ncbo.tree.css">
<script src="//ajax.googleapis./ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="../src/widgets/jquery.ncbo.tree-2.0.2.js"></script>
Share Improve this question edited Oct 11, 2018 at 19:30 msanford 12.3k13 gold badges71 silver badges98 bronze badges asked Oct 11, 2018 at 19:23 Bryan BastidaBryan Bastida 331 gold badge4 silver badges9 bronze badges 1
  • 1 You will very likely experience issues trying to use Angular with jQuery. It is remended you find angular patible modules so that you can ensure they can hook into the Angular ponent lifecycle and rendering. – Alexander Staroselsky Commented Oct 11, 2018 at 19:34
Add a ment  | 

1 Answer 1

Reset to default 2

if you are using angular6 then you can place it inside the script[] section of angular.json file or for angular 4/5 filename is .angular-cli

"scripts": [
    "path/to/scripts/file1.js",
    "path/to/scripts/file2.js"
]

Your below coce might not be working because at that time, "#widget_tree" node is not been created in DOM, just try to add these code in some setTimeout()

<script>
  var widget_tree = $("#widget_tree").NCBOTree({
     apikey: "<my-api-key>",
     ontology: "ENVO"
  });
</script>

like

    <script>
    function injectAPIKey() {
        setTimeout(function() {
          var widget_tree = $("#widget_tree").NCBOTree({
             apikey: "<my-api-key>",
             ontology: "ENVO"
          });
        }, 10000);
    }

injectAPIKey();

</script>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745156194a4614136.html

相关推荐

  • javascript - Using script tag in Angular 6 component.html - Stack Overflow

    I'm aware that Angular removes the script tags in the ponent.html files, but from all the differen

    6小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信