[英]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标签?
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.