0

angular js code

angular.module('myapp')
  .controller('PostsController',  function($scope, $window, $http){

  $scope.$watch('selectedCities', function(newValue, oldValue) {
     if(newValue === oldValue ){
      return;
    }
    //to call a jQuery variable wookmark

  }, true);
}

jquery code

 $(function ($) {
      var container = '#wookmark_container',
          $container = $(container),
          tileCount = 30,
          $window = $(window),
          $document = $(document),
          wookmark;

      // Initialize Wookmark
      wookmark = new Wookmark(container, {
        offset: 5, // Optional, the distance between grid items
        outerOffset: 10, // Optional, the distance to the containers border
        itemWidth: 260, // Optional, the width of a grid item
        autoResize: true
      });

    });

What I am trying to do is if a select options changes I would like to reload a wookmark jquery plugin.

Is it doable to call a jquery vairable in angularjs?

Thanks for any help.

1
  • You need to create directive for this one. Commented Apr 4, 2015 at 4:28

2 Answers 2

1

You can reference any variable that's in the scope of your Angular controller.

It looks like you have woodmark defined inside its own function scope, which means you don't have access to it. To access it, you need to set it as a property of the global window object like so:

window.woodwork =  "initial value";

You can then reference it in your controller using $window service.

$window.woodwork = "updated value";
Sign up to request clarification or add additional context in comments.

Comments

1

Try this,

  1. Declare variable 'wookmark' in the parent or global scope i.e. outside ready block. This will make that variable accessible in the everywhere. You will be able to access it in angular's controller

    var woomark;
    
    $(function ($) {
       // Initialize Wookmark
       wookmark = new Wookmark(container, {...});
    });
    
  2. To reload the woomark plugin, you can give a call as shown below in your code.

    angular.element(document.querySelector('#wookmark_container')).trigger('refreshWookmark');

or directly

$('#wookmark_container').trigger('refreshWookmark')

Here is the documentation link for 'refreshWookmark' https://github.com/GBKS/Wookmark-jQuery

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.