This code below uses Javascript and PHP, but when it runs I want each echo to be on a separate line. I have tried using \n and <br> and other methods but all of them dont have any effect on the text. Can anyone please help me?
function MyCtrl($scope) {
$scope.environment_service_packages =
[
{name: 'obj1', info: {text: '<?php echo "hello" . "\n" . "<br>" . "world"; ?>', show: true}},
{name: 'obj2', info: {text: 'some extra info for obj2', show: false}},
];
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app>
<table ng-controller="MyCtrl" class="table table-hover table-striped">
<tr class="info">
<td>...</td>
</tr>
<tbody ng-repeat="x in environment_service_packages">
<tr ng-click="x.info.show = !x.info.show">
<td> {{ x.name }}
</tr>
<tr ng-show="x.info.show">
<td>
{{ x.info.text }}
</td>
</tr>
</tbody>
</table>
</body>
Edit: For some reason this snippet does not interpret the php.
<br>should work in this case. You can do a small proof by writing your content manually in the html. Why (what's the effect) do you say they didn't work? Did they render as text? If so, it is probably your framework or engine escaping it to output a text form. Or a CSS thing? Hard to say without a minimal complete example. However, br tags inside a td do produce a newline :)<td ng-bind-html="x.info.text"></td>BTW - The whole idea of angularjs is NOT to have PHP injected in the client side..........