0

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 ?

2 Answers 2

1

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;
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you ! I use this with the @Sandeep Panda's anwser !
1

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.