首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将脚本js添加到角9项目中

问将脚本js添加到角9项目中
EN

Stack Overflow用户
提问于 2020-08-07 14:23:58
回答 1查看 723关注 0票数 0

我尝试将script.js添加到angular.json中,并在一个组件中使用它,这样对那些可以建议将脚本标记添加到我的html文件的人来说是行不通的,这不是一个好主意,所以请有人提出另一个想法,或者让我的脚本工作所遗漏的内容。谢谢

这是我的剧本:

代码语言:javascript
复制
$('.owl-carousel').owlCarousel({
loop:true,
margin:10,
dots:false,
nav:true,
mouseDrag:false,
autoplay:true,
animateOut: 'slideOutUp',
responsive:{
    0:{
        items:1
    },
    600:{
        items:1
    },
    1000:{
        items:1
    }
}
});

file.html:

代码语言:javascript
复制
<header>

  <div class="owl-carousel owl-theme">
      <div class="item">
          <img src="https://cdn.pixabay.com/photo/2017/10/24/10/30/business-2884023_960_720.jpg" alt="images not found">
          <div class="cover">
              <div class="container">
                  <div class="header-content">
                      <div class="line"></div>
                      <h2>Teimagine Digital Experience with</h2>
                      <h1>Start-ups and solutions</h1>
                      <h4>We help entrepreneurs, start-ups and enterprises shape their ideas into products</h4>
                  </div>
              </div>
           </div>
      </div>                    
      <div class="item">
          <img src="https://cdn.pixabay.com/photo/2016/03/09/09/22/workplace-1245776_960_720.jpg" alt="images not found">
          <div class="cover">
              <div class="container">
                  <div class="header-content">
                      <div class="line animated bounceInLeft"></div>
                      <h2>Reimagine Digital Experience with</h2>
                      <h1>Intelligent solutions</h1>
                      <h4>We help entrepreneurs, start-ups and enterprises shape their ideas into products</h4>
                  </div>
              </div>
           </div>
      </div>                
      
</header>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-08-07 14:46:33

方法1:

  • 引用ange-cli.json(使用角6+时的angular.json)文件中的脚本。

“脚本”:“./path”;

然后添加typings.d.ts (如果不存在,则在src中创建此文件)

声明var variableName:any;

在您的文件中导入它作为

从'variableName';导入*作为变量

参考https://stackoverflow.com/a/44817445/9640128

方法2:

  • 您可以在组件动态加载

时添加多个脚本

参考资料:https://stackoverflow.com/a/49981918/9640128

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63303759

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档