I need to pass php variable as parameter to angulaJs function. But I am not getting the WordPress parameter in Angularjs function. I am getting undefined
in AngularJs function.
My code :
<div class="ind-wrapper" data-ng-controller="mainController" data-ng-init="init(<?php echo get_the_title(); ?>)">
</div>
AngularJs function:
Here I am getting title name is undefined
$scope.init = function (titlename)
{
alert(titlename)
}
Please help!!
You need to encode echoed variable properly, for example using
json_encode
function which will ensure that your title has proper quotes:If you know that the title doesn’t contain special characters or other quotes you can also simply do this: