1

In AngularJS I could do:

<img ng-src="https://someimageurl/{{ foo.replace('bar','') }}" />

How can I achieve the same result in DOM with AngularJS 2?

2 Answers 2

2

This

<img ng-src="https://someimageurl/{{ foo.replace('bar','') }} />

is not an angular replace method, is just the javascript replace method being called inside angular interpolation.

In angular2, you can do the same by doing:

<img [src]="'https://someimageurl/' + foo.replace('bar','')"/>

You can find more information about Template Syntax in Angular 2 docs.

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

Comments

1

Like this:

<img [src]="'https://someimageurl/' + foo.replace('bar','')" />

2 Comments

Works quite nicely, thanks. Doesn't feel very Angular though. Before I accept the answer, is there a "recommended" way to do angular's deprecated .replace?
@JavaNoob No, there is no .replace method in angular. You need to do like JavaScript replace in the markup or in the Angular 2 Component.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.