Created
October 10, 2015 16:16
-
-
Save amielucha/56e7d09cb7f570296f0b to your computer and use it in GitHub Desktop.
AngularJS ♥ WordPress Tutorial part 9 #tutorial
This file contains hidden or 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
(function(){ | |
var app = angular.module('angular♥wp', ['ngRoute']); | |
var api = {}; | |
// JSON content location | |
api.query = 'http://amielucha.com/wp-json/wp/v2/posts/'; | |
app.config(function($routeProvider, $locationProvider){ | |
// Enable html5 mode | |
$locationProvider.html5Mode(true); | |
// configure routing | |
$routeProvider.when('/', { | |
templateUrl: 'content.html', | |
controller: 'Main', | |
}); | |
}); | |
app.controller('Main', ['$scope', '$http', '$routeParams', '$sce', function($scope, $http, $routeParams, $sce){ | |
$http.get( api.query ).success(function(res){ | |
// iterate through each field to set it as trusted | |
angular.forEach($scope.posts, function(value, key) { | |
// trust each title and excerpt in the object | |
this[key].title.rendered = $sce.trustAsHtml(value.title.rendered); | |
this[key].excerpt.rendered = $sce.trustAsHtml(value.excerpt.rendered); | |
}, $scope.posts); | |
}); | |
}]); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment