简体   繁体   English

Angular:如何在组件模板中使用index.html中引用的JavaScript?

[英]Angular: how can I use JavaScript referenced in index.html in a component template?

Angular newbie here. 这里有角的新手。

I have a color picker (jscolor) which works perfectly in my index.html, but I can't seem to use it the same way via my component template. 我有一个颜色选择器(jscolor),可在我的index.html中很好地工作,但似乎无法通过组件模板以相同的方式使用它。

I have a script tag reference to it in the head of index.html. 我在index.html的头中有一个脚本标记引用。 If I use the tag in index.html, it works perfectly. 如果我在index.html中使用标记,则效果很好。 However, if I use in a component template, it doesn't work at all. 但是,如果我在组件模板中使用它,则根本无法使用。 I thought after transpilation, the template code would read as part of index.html. 我认为在编译之后,模板代码将作为index.html的一部分读取。

How can I use the jscolor associated html tag in my component template? 如何在组件模板中使用jscolor关联的html标签?

JSColor documentation here JSColor文档在这里

You need to properly inject the library to the code and execute it once your application is loaded. 您需要正确地将库注入代码中,并在应用程序加载后执行它。

Not sure which angular version you are using, but those threads might help you: 不知道您使用的是哪个角度版本,但是这些线程可能会帮助您:

AngularJS JSColor pick up color to trigger AngularJS ng-change AngularJS JSColor拾取颜色以触发AngularJS ng-change

Angular Importing jscolor library in angular 2 Angular 2中的 Angular 导入jscolor库

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 angular 8 中获取 index.html 模板上的组件值? - How to get component value on index.html template in angular 8? 如何将文件 vuejs 组件导入 index.html? - how can I import a file vuejs component into index.html? 如何在索引中使用 *ngIf.html angular 8 - How to use *ngIf in index.html angular 8 Angular 在 index.html 中导入脚本并在组件中使用 - Angular import script in index.html and use it in component Angular2:如何使用 Javascript 从 index.html 访问 DOM-Element(组件内部) - Angular2: How to access DOM-Element (inside Component) from index.html with Javascript 如何从 index.html 获取值并在解析 JSON 文件后使用它来呈现第二个模板? - How can I get a value from index.html and use it to render a second template after parsing JSON file? 如何直接在index.html文件上加载Angular2组件? - How to load an Angular2 component directly on the index.html file? 删除index.html中的url,但是如何在app.component.ts中使用它们 - removing url in index.html but how can i have them in app.component.ts Reactjs 我如何使用 Typescript 将道具从 index.html 传递到 App 组件 - Reactjs How i can pass props from index.html to App component with Typescript 如何在脚本标签的index.html中使用Bowser Javascript库? - How to use a Bowser Javascript Library in index.html in script tags?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM