Home > database >  Setting Img src attribute in Angular produces error
Setting Img src attribute in Angular produces error

Time:03-29

<div ng-repeat="file in files" >
    <div >
        <div ng-if="!(file.thumbnail === '')" >
            <img  ng-src="{{ file.thumbnail }}" />
        </div>
        <div >
            <a >
                <span ng-click="getFile(file.id,file.extension,file.fileName)">{{ file.fileName }}</span>
            </a>
            <div >
                <span>{{ file.fileSizeByte }}</span>
            </div>
        </div>
    </div>
</div>

Angular Version is 1.3.14. The Code worked fine (functions worked and all outputs) until I added ng-src="{{ file.thumbnail }}". This gives me the error Unknown provider: urlattrFilterProvider <- urlattrFilter . Even outputting {{ file.thumbnail }} as text outside of the attribute works fine. Is this way not correct for setting the src of an image?

CodePudding user response:

Just use src="{{file.thumbnail}}" instead of ng-src="{{file.thumbnail}}"

CodePudding user response:

Not an actual answer but might be helpful: the Unknown provider:... error usually shows up when we are injecting something to an angular module the wrong way, eiher a mispelled dependency or a dependency injected in the wrong order. Make sure the error is coming where you're expecting it from, you can just set a breakpoint on exceptions and confirm this.

  • Related