0

I'm creating a lightning component named "scroll" and a controller file associated with it. Here's the opening tag of .cmp file:

<aura:component controller="scrollController" implements="force:appHostable,flexipage:availableForAllPageTypes,forceCommunity:availableForAllPageTypes" access="global" >

Every time I try to save the .cmp file, I get this error:

Failed to save scroll.cmp: Invalid definition for null:scrollController: null: Source

If I remove controller="scrollController" it will save no problem.

I stripped down the controller file to just a simple alert to weed out any possible JS issues:

({
     scroll: function() {


            alert('this works');


    },    
})
  • 1
    Do you have an Apex class named scrollController available? – Jayant Das Dec 27 '18 at 18:10
  • 1
    Do you have an Apex Class named scrollController? If so please share it here. – Adrian Larson Dec 27 '18 at 18:10
1

The controller attribute is used for an Apex class. You do not specify this attribute for any of the source files (e.g. scrollController.js in your bundle). You would use the controller attribute to access Apex code methods, such as performing DML, querying data, or making callouts.

  • Ah, I see. Lightning Components are meant to control server side functionality. I'm trying to implement a scroll animation work-around. Looks like a component is not the place for this. – Eric Nguyen Dec 27 '18 at 18:15
  • @EricNguyen No, components are meant to be primarily client-side logic with a way to interact with the server as necessary. If you're trying to make a scroll animation wrapper, a component is probably a correct solution. – sfdcfox Dec 27 '18 at 18:17
  • What would you recommend for animations? I've tried using "edit head markup" and include all JS files there (which I know is not good practice but the only place I can find to include) however not working w/ the library I'm working with. FYI, using scrollmagic library which doesn't work but AOS library works. – Eric Nguyen Dec 27 '18 at 18:19
  • @EricNguyen Not all libraries are compatible, but you might be able to implement keyframe animations (CSS), or, as long as you're wrapping the components in your own HTML, you can animate those directly. Your problem is likely related to Locker Service. – sfdcfox Dec 27 '18 at 18:21
0

In Lightning Aura Components, there are essentially two types of Controllers:

  1. JavaScript Controller. The one which is part of the aura bundle. E.g., if you have a component named myComponent.cmp, then the JS controller for this will be myComponentController.js. You don't specify this controller anywhere in your component and the framework is aware of the corresponding controller JS for your component.
  2. Apex controller. This is used when you need to communicate with the server to perform additional operations. This is when you use the controller attribute in your component (.cmp file) to specify the Apex controller for the component.

In your case, it seems you are referring to the JS file using the controller attribute, which is not required here.

If you need more details on apex controllers and calling server side actions, you can refer to its documentation here.

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.