I Managed to get it working by firstly moving the initial variable declarations in custom.js to a function.
var CURRENT_URL = '',
$BODY = '',
$MENU_TOGGLE = '',
$SIDEBAR_MENU = '',
$SIDEBAR_FOOTER = '',
$LEFT_COL = '',
$RIGHT_COL = '',
$NAV_MENU = '',
$FOOTER = '';
function init_vars() {
CURRENT_URL = window.location.href.split('#')[0].split('?')[0];
$BODY = $('body');
$MENU_TOGGLE = $('#menu_toggle');
$SIDEBAR_MENU = $('#sidebar-menu');
$SIDEBAR_FOOTER = $('.sidebar-footer');
$LEFT_COL = $('.left_col');
$RIGHT_COL = $('.right_col');
$NAV_MENU = $('.nav_menu');
$FOOTER = $('footer');
}
then inside your angular controller js file you need to add a run method that listens to the ngInclude '$includeContentLoaded' emitter.
in my case i am using an ng-include for the side-menu called menu.html
<div ng-include="'menu.html'" id="sidebar-menu" class="main_menu_side hidden-print main_menu"></div>
The 'menu.html' filename is what the second parameter (templateName) in the function will pick up.
init_vars() is then called to define the global variables after the DOM has been loaded.
We can then call the relevant inits based on what has been loaded as shown below.
app.run(function ($rootScope) {
$rootScope.$on("$includeContentLoaded", function (event, templateName) {
init_vars(); //my defined function to load global variables after dom has been loaded
if (templateName == 'menu.html') { //checking if this ng-include is the one that has loaded
init_sidebar();
//... other init functions
}
});
});
You will have to disable the call in custom.js that is triggered after the DOM has loaded that initializes everything.
So the below code should be commented out in your custom.js file.
$(document).ready(function () {
init_sparklines();
init_flot_chart();
init_sidebar();
init_wysiwyg();
//...other inits
});
If you run into issues with constant reloading just add a global variable that indicates whether the scripts have been loaded.