0

I'm doing some testing with AngularJS and WordPress but I can't seem to figure out how to get ng-view to work with WP. My knowledge about WP/php is extremely limited and I should probably do more tutorials on those before trying to do what I'm trying to do (I'm planning to do that after I solve this problem).

There are no folders in my theme. Here is my code:

header.php

<!DOCTYPE html>
<html <?php language_attributes(); ?> ng-app="myTestApp">
    <head>
        <title>My Test Theme</title>
        <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>">
        <?php wp_head(); ?>
    </head>
    <body>
    <p>header</p>

index.php

<?php get_header(); ?>
<div ng-controller="homeController">
    <a href="#home">Home</a>
    <a href="#my_page">My page</a>
    <div ng-view></div>
</div>
<?php get_footer(); ?>

footer.php

<p>footer</p>
<?php wp_footer(); ?>        
</body>
</html>

app.js

    var myTestApp = angular.module('myTestApp', ['ngRoute']);

myTestApp.config(function($routeProvider){
  $routeProvider
    .when('home', {
      templateUrl: 'home.php',
      controller: 'homeController'
    })
    .when('my_page', {
      templateUrl: 'my_page.php',
      controller: 'koncertyController'
    });
});

myTestApp.controller('homeController', function($scope){
});

myTestApp.controller('my_pageController', function($scope){
});

functions.php

    <?php 
function my_test_theme_enqueue_scripts() {
  // enqueue jQuery and AngularJS
  wp_register_script('angular-core', 'https://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.js', array(), null, false);
  wp_enqueue_script('angular-route', '//ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular-route.min.js', array('angular-core'), null, false);
  wp_register_script('angular-app', get_bloginfo('template_directory').'/app.js', array('angular-core'), null, false);

  // enqueue all scripts
  wp_enqueue_script('angular-core');
  wp_enqueue_script('angular-route');
  wp_enqueue_script('angular-app');
  wp_enqueue_script('angular-directives');
}
add_action('wp_enqueue_scripts', 'my_test_theme_enqueue_scripts');
?>

I believe the problem lies in functions.php. Thanks!

1
  • What errors are in the console? Commented Sep 10, 2015 at 20:01

1 Answer 1

-1

I believed your problem relies on the php files since php files generate html on the server side. Since Angularjs is a client-side framework you can't get that working for you.

Sign up to request clarification or add additional context in comments.

2 Comments

This doesn't really answer the question.
Just clarifying that there is nothing in php preventing you from integrating Angular to a page generated using php. Apologies I've no experience of WP

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.