Getting AngularJS to work within a Drupal install

A Blog Post by

To embed AngularJS (1.0.1) in a Drupal (6.x) site won't work out of the box. To get AngularJS to function you need to upgrade your jQuery to the latest 1.7.x version as the packaged jQuery and jquery update (1.3.2) will break AngularJS.

Now for the solution:
1. Install the latest dev version of jQuery Update and make your default jQuery 1.7.
This That removed some errors but didn't quite cut it.

2. Replace your misc/jquery.js with the latest jquery-1.7.x.min.js.
Ok now the errors are sorted for AngularJS, but there is a compatability issue with jQuery 1.7.x and Drupal 6.x not yet fixed by jquery_update-6.x-2.x-dev (2012-Jan-20).

3. Patch the misc/tabledrag.js file with the following:

diff --git a/misc/tabledrag.js b/misc/tabledrag.js
--- a/misc/tabledrag.js
+++ b/misc/tabledrag.js
@@ -171,7 +171,7 @@ Drupal.tableDrag.prototype.makeDraggable = function(item) {
   // Create the handle.
   var handle = $('<a href="#" class="tabledrag-handle"><div class="handle">&nbsp;</div></a>').attr('title', Drupal.t('Drag to re-order'));
   // Insert the handle after indentations (if any).
-  if ($('td:first .indentation:last', item).after(handle).size()) {
+  if (self.indentEnabled && $('td:first .indentation:first', item).size() && $('td:first .indentation:last', item).after(handle).size()) {
     // Update the total width of indentation in this entire table.
     self.indentCount = Math.max($('.indentation', item).size(), self.indentCount);
   }

4. Patch views/js/dependent.js

diff --git a/js/dependent.js b/js/dependent.js
index 7683fdd..afdf522 100644
--- a/js/dependent.js
+++ b/js/dependent.js
@@ -91,7 +91,7 @@ Drupal.Views.dependent.autoAttach = function() {
         else {
           switch (jQuery(trigger).attr('type')) {
             case 'checkbox':
-              var val = jQuery(trigger).attr('checked') || 0;
+              var val = jQuery(trigger).attr('checked') ? true : false;

This fixes the checkbox issue in view admin fields.

Hope this helps someone else.

It's working quite well.. so far :)

Created: Mon, 30/07/2012 - 18:47