I need to delay AngularJS scripts from running so I can set up my application first. I need to initialize the application with ng-app="app". I want to add that attribute to the < body >
< body ng-app="app" >< /body >
wp_enqueue_script('plugin-setup', plugin_dir_url( __FILE__ ).'js/plugin-setup.js', array('jquery'), null, true);
plugin-set.js
document.addEventListener("DOMContentLoaded", function(event) {
document.getElementsByTagName("body")[0].setAttribute("ng-app", "app");
});
After that is set up I can run my Angular Scripts:
class pluginClass{
function pluginInit(){
add_action( 'wp_enqueue_scripts', array( $this, 'scriptThings' ) );
}
function scriptThings(){
wp_enqueue_script('angular-core', plugin_dir_url( __FILE__ ).'js/vendor/angular/angular.js', array('jquery'), null, true);
wp_enqueue_script('angular-resource', plugin_dir_url( __FILE__ ).'js/vendor/angular-resource/angular-resource.js', array('jquery'), null, true);
wp_enqueue_script('app', plugin_dir_url( __FILE__ ).'js/app.js', array(), null, true);
wp_enqueue_script('app-controller', plugin_dir_url( __FILE__ ).'js/controllers/app_controller.js', array(), null, true);
wp_enqueue_script('imagetile-factory', plugin_dir_url( __FILE__ ).'js/resource/imageTile_factory.js', array(), null, true);
}
}
$my_class = new pluginClass;
add_action('init', array($my_class, 'pluginInit'));
Is there a way to delay the Angular scripts from loading within my plugin.php*?