I have a code in angularjs which loops an ajax json response like this:
<div ng-repeat="post in posts">
{{post.title}}
{{post.url}}
</div>
It works fine. How do I do to pass a PHP variable based on the json?
Lets say the json looks have a structure this:
post
my_slug
my_title
post
my_slug2
my_title2
I have a PHP array like this:
my_slug
url
my_slug2
url2
my_slug in PHP matches my_slug in json.
Ajax call
var app = angular.module("MyApp", []);
app.controller("PostsCtrl", function($scope, $http) {
$http.get('<?php echo u(); ?>test/json.txt').
success(function(data, status, headers, config) {
$scope.posts = data;
}).
error(function(data, status, headers, config) {
});
});
The result should look somethins like this:
<div>
my_title
url
</div>
<div>
my_title2
url2
</div>
In the angularjs json loop I want to get url
and url2
from my PHP array. How? Can I pass the PHP array with my Ajax response?