1

I just migrated from Magento 1.x to Magento 2.

I setup Magento successfully, understood and used RequireJS as well.

I was adding flexslider on my home page and got the error:

$ is not a function

which means either jQuery is not loaded or there is a conflict. When I checked the network, I see jQuery is loaded successfully and jquery.flexslider-min.js is loaded after jQuery.

So, I'm not able to find the problem.

Here is my requirejs-config.js under my theme directory:

var config = {
map: {
    '*': {
        flexslider: 'Mymodule_Test/js/jquery.flexslider-min',
        header: 'Mymodule_Test/js/store/header'
    }
}
}; 

and there is part of my template:

<script type="text/javascript">

require(['jquery', 'flexslider'],function($, flexslider){
    (function() {
        $(window).load(function () {
            $('.flexslider').flexslider();
        });
    })(jQuery);
});
</script>

Please help me!

2

try this :

require(['jquery', 'flexslider'], function($) {
    $(document).ready(function($) {
        $('.flexslider').flexslider();
    });
});

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.