Maybe something like this:
var items = $scope.project.perso.split('-');
if (items.length > 1) {
var list = "";
for (var i = 0; i < items.length; i++) {
list += "<li>" + items[i] + "</li>";
}
$scope.project.perso = list;
}
Вопрос
I have several $scope
with content.
HTML :
<td>{{ project.captation }}</td>
<td>{{ project.perso }}</td>
Output :
content1
Random text here...
content2
- Lorem ipsum- quia dolor sit ame- consectetur adipiscing elit
JS (controller) :
$http({
url: "php/random.php",
method: "GET"
}).success(function(data) {
$scope.project = data;
});
I would like to replace each -
by <li>....</li>
only in the case where there is a -
.
How to do this ?
Решение
Maybe something like this:
var items = $scope.project.perso.split('-');
if (items.length > 1) {
var list = "";
for (var i = 0; i < items.length; i++) {
list += "<li>" + items[i] + "</li>";
}
$scope.project.perso = list;
}
Другие советы
You need to create a custom filter which replaces -
with <li>...</li>
. See this link to get started with filters. Then use the filter as following in your HTML template:
<td>{{ project.captation | filterNameHere }}</td>
<td>{{ project.perso | filterNameHere }}</td>