Last active
June 12, 2019 08:39
-
-
Save yoren/64db51f26341939214c6 to your computer and use it in GitHub Desktop.
Display WordPress posts with AngularJS and JSON API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ul> | |
<li ng-repeat="post in posts"> | |
<a href="{{post.ID}}"> | |
{{post.title}} | |
</a> | |
</li> | |
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('app', ['ngRoute']) | |
.config(function($routeProvider, $locationProvider) { | |
$locationProvider.html5Mode(true); | |
$routeProvider | |
.when('/', { | |
templateUrl: myLocalized.partials + 'main.html', | |
controller: 'Main' | |
}); | |
}) | |
.controller('Main', function($scope, $http, $routeParams) { | |
$http.get('wp-json/posts/').success(function(res){ | |
$scope.posts = res; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This gist is part of my post: Using AngularJS And JSON API In Your WordPress Theme