Kikz Kikz - 2 months ago
233 0

I am having a problem here.
When I'm passing the value of {{ post.country}} on my controller.
Instead of transferring the real value. its gives the value as " {{ post.country}}"

So when the console.log(country);
The result is {{ post.country}}

It should be name of the value

AngularJS

How to pass expression value on ng-init?

<ul ng-controller="mycontroller4">
<div ng-repeat="post in posts">

   <div ng-controller="mycontroller5" ng-init='init("{{ post.country}}")'>

   </div>
</div>
</ul>

<script>
myapp.controller( 'mycontroller5', ['$scope', '$http', function( $scope, $http ) {
	
	
	$scope.init = function(country) {
		$scope.country= country;
		// Load posts from the WordPress API
		$http({
			method: 'POST',
			url: "/wp-admin/admin-ajax.php",
			params: {
				action: "FUNCTION",
				country: $scope.country,
			},
			headers : { 'Content-Type': 'application/x-www-form-urlencoded' }
		}).
		success( function( data, status, headers, config ) {
			console.log(country);
			$scope.posts = data;
		}).
		error(function(data, status, headers, config) {	
		});	
	}
  
}]);
</script>
Comments