Simple integration of WP and AngularJS
-
I’m relatively new to both WP and AngularJS. I want to do some simple, lightweight proof of concept stuff locally to help my understanding.
I can get the Angular component to work independently of WP by simply copying any example from here and serving it directly (nothing to do with WP) from my local Apache web server.
I want to be able to integrate the same AngularJS example into a WP constructed page.
I an suspicious that loading the angular.min.js library is causing the issue.
I have tried a number of things, all of which yield the same result – namely a page showing unparsed AngularJS content. See screenshot here
I have added the relevant code to a Gutenberg HTML block. I have tried loading the angular.min.js library using a variety of methods …
1
By directly including it in the Gutenberg block (i didn’t really expect that to work anyway – though it did when including it similarly in my other directly served page test outside of WP).2
By coding it in a sample template page, with and without first registering it … i.e. either …wp_register_script('angularjs', '/wp-content/themes/twentynineteen/angularjs/angular.min.js'); wp_enqueue_script('angularjs');or …
wp_enqueue_script( 'angularjs', '/wp-content/themes/twentynineteen/angularjs/angular.min.js');In the
wp_enqueue_scripti have verified thatangular.min.jsis correctly pathed. I have also experimented with passing the CDN URL towp_register_script/wp_enqueue_script, as well as using bothtrueandfalseas values for the enqueue function’s$in_footer = falseargument.In all cases i get the same result. As shown in the screenshot.
Can anyone point out what i might need to do to get this working? I don’t want to mask my understanding by doing anything too involved. In my mind it’s a simple idea …. load the AngularJS library then execute the code.
Thx
The topic ‘Simple integration of WP and AngularJS’ is closed to new replies.