0

How can I replace a string in angular js?

This is what I have tried:

HTML:

<tr ng-attr-id="filter_id(event.kibana._source._id)"></tr>

JS:

$scope.filter_id = function(id){
    return id.replace(":","-");
}

But the id won't fill..

3
  • what do you mean "id won't fill"? Or can you give an example of id you try to pass to the function? Commented Jul 7, 2015 at 13:50
  • I mean the id remains empty in the DOM. Commented Jul 7, 2015 at 13:56
  • One variable cloud be event.kibana._source._id = "test:test:test", but I want it to be "test-test-test" Commented Jul 7, 2015 at 13:57

1 Answer 1

3

Seems you forgot to add the double-braces {{}} around the call:

<tr ng-attr-id="{{filter_id(event.kibana._source._id)}}"></tr>

Here's a Plnkr showing it works. Also note that I changed your filter_id function to use regex for the string replace. As it stands your function would only replace the first occurrence of a :.

Sign up to request clarification or add additional context in comments.

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.