简体   繁体   English

ESLint抱怨Angular应用中的GreenSock

[英]ESLint complaining about GreenSock inside Angular app

I'm working on a small Angular app which is using GreenSock's Draggable plugin. 我正在使用GreenSock的Draggable插件开发一个小的Angular应用程序。 Everything works as expected; 一切都按预期进行; however, I'm using ESLint and it is complaining that TweenMax and Draggable are not defined. 但是,我使用的是ESLint,并且抱怨没有定义TweenMax和Draggable。

74:7   error  "Draggable" is not defined                                            
133:7   error  "TweenMax" is not defined
133:78  error  "Bounce" is not defined

I have function that sets up a draggable element in my controller and a few tweens in the controller as well: 我具有在控制器中设置可拖动元素以及在控制器中设置一些补间的功能:

// Set up GreenSock Draggable dial
function setUpDraggableElement(element) {
  Draggable.create(element, {
    type: 'rotation',
    onPress: onDialTouch,
    onRelease: onDialRelease,
    onDrag: onRotateDial,
    liveSnap: function(endValue) {
      return Math.round(endValue / 20) * 20;
   }
  });
}

...

TweenMax.to(angular.element('.selector'), 0.5, { scale: 1.1, ease: Bounce.easeOut});

I'm new to Angular; 我是Angular的新手。 do I need to wrap them in some sort of directive or something? 我需要将它们包装在某种指令之类的东西中吗?

If your application works as expected, I believe this is just a problem with ESLint. 如果您的应用程序按预期运行,我相信这只是ESLint的问题。

GSAP is defining "Draggable", "TweenMax", and "Bounce" in one file (or each in its own file) and you are using those names in a different file. GSAP在一个文件(或每个文件在其自己的文件)中定义“可拖动”,“ TweenMax”和“反弹”,而您在另一个文件中使用这些名称。 ESLint looks at the files individually , so it is warning that the names have not been defined. ESLint着眼于单独的文件,因此它警告说,名字尚未确定。

What you need to do is notify ESLint that "Draggable", "TweenMax", and "Bounce" are global variables (defined outside of the file). 您需要做的是通知ESLint,“ Draggable”,“ TweenMax”和“ Bounce”是全局变量(在文件外部定义)。 Something like this: 像这样:

/*global Draggable, TweenMax, Bounce*/

Here is the full list, just add it to the ESList config file the same way (I assume its the same way, I'm currently using JSHint). 这是完整列表,只需以相同的方式将其添加到ESList配置文件中(我以相同的方式假设,我目前正在使用JSHint)。

https://greensock.com/forums/topic/13416-using-tweenmaxgsap-with-gulp/ https://greensock.com/forums/topic/13416-using-tweenmaxgsap-with-gulp/

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM