Exploring the world of Angular with Bookblock JS

I have integrated Bookblock with angularJS successfully on the first page load. However, I encountered an issue when trying to turn the page, resulting in the following error:

TypeError: config.$bookBlock.bookblock is not a function

Controller.js

'use strict';

angular.module('myApp.controllers', [])

service:

.service('myService', function () {
 return {
  fn: function () {
          var Page = (function() {
            var config = {
                $bookBlock : $( '#bb-bookblock' ),
                $navNext : $( '#bb-nav-next' ),
                $navPrev : $( '#bb-nav-prev' ),
                $navFirst : $( '#bb-nav-first' ),
                $navLast : $( '#bb-nav-last' )
            },
            init = function() {
                console.log("2 .inside init....");
                config.$bookBlock.bookblock( {
                    speed : 1000,
                    shadowSides : 0.8,
                    shadowFlip : 0.4
                } );
                console.log("2.5 .at last init.... ");
                initEvents();
            },
            initEvents = function() {
                console.log("3 .inside init event....");
                var $slides = config.$bookBlock.children();

                // add navigation events
                config.$navNext.on( 'click touchstart', function() {
                    config.$bookBlock.bookblock( 'next' );
                    return false;
                } );

                config.$navPrev.on( 'click touchstart', function() {
                    config.$bookBlock.bookblock( 'prev' );
                    return false;
                } );

                config.$navFirst.on( 'click touchstart', function() {
                    config.$bookBlock.bookblock( 'first' );
                    return false;
                } );

                config.$navLast.on( 'click touchstart', function() {
                    config.$bookBlock.bookblock( 'last' );
                    return false;
                } );

                // add swipe events
                $($slides).on( {
                    'swipeleft' : function( event ) {                                
                        config.$bookBlock.bookblock( 'next' );
                        return false;
                    },
                    'swiperight' : function( event ) {                               
                        config.$bookBlock.bookblock( 'prev' );
                        return false;
                    }
                } );

           // additional code removed for brevity    
            };
            return { init : init };

        })();
          Page.init(); 
       }
     }
 })

Main Controller :

.controller('MainCtrl', ['$scope', 'FeedService','$http','$rootScope', '$window', '$location','myService','$route', function ($scope,Feed,$http, $rootScope, $window, $location, myService, $route) 
{    
    console.log("inside main controller");
    $scope.slides = '';
    $scope.goCats = false;
    $scope.menu_item_names = ['Insights and Publications', 'McKinsey News ', 'Recomanded Reading', 'Alumni News', 'McKinsey Bookshelf','McKinsey Talks', 'Know', 'McKinsey Calendar', 'Engagement Channel', 'McKinsey Technology Site'];
    myService.fn();                      //calling service
    console.log("inside main last line");
}])    

Second Controller :

 .controller('secondPageControllers',  ['$scope', '$rootScope','myService','paging' , '$window', '$location', 'Story', '$routeParams',  function ($scope, $rootScope, myService, paging, $window, $location, Story , $routeParams) 
  {
    console.log('secondPageControllers')
    console.log($routeParams.templateID + "params 1");
    $scope.slide = '';

    Story.query({}, 
      function success(data) {
        console.log(data.length);
         $scope.stories = data ;
         $scope.templateID = $routeParams.templateID;
         console.log(data);
      }, 
      function err() {
        console.log('error')
      });
    myService.fn(); 

 }])

If anyone has a solution, please share it...

Answer №1

To resolve this issue, I successfully implemented a directive to incorporate the necessary functionality. Ensure that you include the required tags for the directive, bb-bookblock class, bb-item, and navigation elements within the HTML structure as outlined in the plugin's documentation.

angular.module('myapp', []).
directive('bookblock', function() {
    return {
    restrict:'AE',
    link: function(scope, element, attrs) {

        bookBlock =  element, // $(element).find("#bb-bookblock"),
        navNext = $(document).find('#bb-nav-next'),
        navPrev = $(document).find( '#bb-nav-prev'),

        bb = element.bookblock( {
            speed : 800,
            perspective : 2000,
            shadowSides : 0.8,
            shadowFlip  : 0.4,
            });

                var slides = bookBlock.children();

                // add navigation events
                navNext.on( 'click touchstart', function() {
                    element.bookblock( 'next' );
                    return false;
                } );

                navPrev.on( 'click touchstart', function() {
                    element.bookblock( 'prev' );
                    return false;
                } );

                // add swipe events
                slides.on( {
                    'swipeleft' : function( event ) {
                        bookBlock.bookblock( 'next' );
                        return false;
                    },
                    'swiperight' : function( event ) {
                        bookBlock.bookblock( 'prev' );
                        return false;
                    }
                } );

                // add keyboard events
                $( document ).keydown( function(e) {
                    var keyCode = e.keyCode || e.which,
                        arrow = {
                            left : 37,
                            up : 38,
                            right : 39,
                            down : 40
                        };

                    switch (keyCode) {
                        case arrow.left:
                            bookBlock.bookblock( 'prev' );
                            break;
                        case arrow.right:
                            bookBlock.bookblock( 'next' );
                            break;
                    }
                } );

    }
    };
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Updating fields in a MongoDB collection with identical names

I am seeking guidance on how to update all instances of 'list_price' within a complex collection like this: "cost_price" : 79.9, "list_price" : 189.9, "sale_price" : 189.9, "integrations" : { "erp" : { "mbm" : { "cost_pri ...

Is it possible that the background color won't change on the second click?

Initially, my first click worked fine and successfully changed the background color. However, as soon as I added a second condition, it stopped working. var showBox = $('.show'); showBox.click(function(){ if (parseInt($(this).attr('v ...

Crafting LayerGroups on the Fly with Leaflet

Dynamic Creation of LayerGroups: Is it Achievable? I am currently working on a web map showcasing the various tree species present in parks. My goal is to create a separate LayerGroup for each species so that users can toggle visibility using a LayerContro ...

The issue arises when PhantomJS and Selenium fail to execute iframe JavaScripts while attempting to log in to Instagram

Currently utilizing Python alongside Selenium and PhantomJS, I encountered an issue while attempting to login to Instagram. It seems that PhantomJS is unable to process iframes' JavaScripts properly; interestingly, when trying the same action with Fir ...

Guide on parsing a JavaScript file and converting the default export module to JSON with Node.js

What I'm trying to accomplish in my Node.js project is reading a sample.js file with ES Module syntax and extracting the default export from it. sample.js import foo from "foo"; const bar = [ { name: "Homer", }, { n ...

Align Horizontal Fixed Element

<html> <head> <style> #rectangle { position: absolute; right: 0; bottom: 0; width: 150px; height: 200px; } </st ...

The behavior of Angular 2 change detection is distinct when utilizing CLI versus webpack

We are currently facing a challenging issue with our application that seems to be related to Angular, Zone, webpack, or angular-cli. The complexity of the problem makes it difficult to reproduce and post as a bug report. That's why I'm reaching o ...

Switch positions of two objects in JavaScript

Check out the code snippet below: MyObject.prototype.doIt = function() { let a = this.obj1; let b = this.obj2; } I need to find a way to switch the values of this.obj1 and this.obj2, making obj1 take on the value of obj2 and vice versa. Pleas ...

Utilizing the NestJS Reflector within a Custom Decorator: A Comprehensive Guide

I have implemented a solution where I use @SetMetaData('version', 'v2') to specify the version for an HTTP method in a controller. Additionally, I created a custom @Get() decorator that appends the version as a suffix to the controller ...

What is the best way to handle multiple JSON data using jQuery?

Understanding how to utilize jquery for parsing simple json is a valuable skill. json { "Symbol": "AAL.L", "Name": "ANGLO AMERICAN", "Last": "3061.50", "Date": "7/26/2011", "Time": "11:35am", "Change": "+3 ...

Retrieving Values from JSON in ASP.NET MVC Using Two Parameters

I have been working on retrieving a value based on 2 parameters. Below is the function I created where I included my parameters in JSON stringify: function GetItemLocationOnHand(itemId, locationId) { var data = JSON.stringify({ itemId: itemId, ...

Activate browser scrollbar functionality

Below is the HTML code snippet: <html> <head> <style> #parent { position : absolute; width : 500px; height : 500px; } #top { position : absolute; width : 100%; height: 100%; z-index : 5; } #bottom { position : absolute; width : 100%; ...

Once appearing, the element quickly vanishes after the fadeIn() function is

In the source code, there is a section that looks like this: <div class="dash page" id="home"> <?php include ('pages/home.php'); ?> </div> <div class="dash page" id="screenshots"> <?php include ('pages/scr ...

arranging and combining data arrays by individual elements

I am looking to group payments by month into a new array, regardless of the account type given by 3 categories (DEA, ISA, SIPP). The data I have is structured as follows: var arr = [ { 'DEA','1', 'Jan',1266 }, ...

Unable to retrieve HTML content through a Node.js server

I created a HTML webpage that includes .css, images and JavaScript files. However, when I start my node server using the command below: app.get('/', function(req, res){ res.sendFile(__dirname + '/index.html'); }); The webp ...

Please note: With React 18, the use of ReactDOM.render is no longer supported. Instead, we recommend using create

I encountered an issue while attempting to link my React application with a MongoDB database. Here is the code snippet where the problem occurred: //index.js ReactDOM.render( <React.StrictMode> <BrowserRouter> <App /> &l ...

Encountering a blank webpage displaying a warning that reads, "The use of 'event.returnValue' is outdated

Although this issue has been discussed before and was previously considered a bug, I am currently using jQuery v1.11.0, which should have resolved it. The problem I am encountering is that when my page loads, there is supposed to be a slide-in effect (as a ...

JavaScript Regular Expression for separating a collection of email addresses into individual parts

I am very close to getting this to work, but not quite there yet. In my JavaScript code, I have a string with a list of email addresses, each formatted differently: var emailList = '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data- ...

The Angular application is not displaying correctly on mobile devices due to a lack

Having an issue with my angular build. I've deployed my website at this link: It appears fine when viewed on a desktop and even in the devtools. However, when I try to access it on my phone, the layout looks terrible! Any suggestions on how to fix ...

Transferring information from a JavaScript function to an action method in an ASP.NET MVC controller

Despite searching through numerous posts on SO in an attempt to solve my problem, I have not made much progress. My goal is to pass data from a JavaScript function (DropdownChange()) to an MVC controller's action method as a parameter based on the sel ...