Search code examples
javascriptangularionic2ionic3

.replace in AngularJs 2


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?


Solution

  • 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.