Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angular scope assign img src will first make a bad request [closed]

this is my web page

<!DOCTYPE html>
<html ng-app>
    <head>
    <meta charset="UTF-8">
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.min.js"></script>
    </head>
    <body ng-controller="imgController">
    <img src={{imgsrc}} />
    <script type="text/javascript">
     var imgController=function($scope){
      $scope.imgsrc='http://su.bdimg.com/static/superpage/img/logo_white.png';
    };
    </script>
    </body>
</html>

this is only an example, I want to get assign a image src via angular scope,but before angular work, the broswer will first requet the url {{imgsrc}}. Of course,it's a bad url, so it's a err, it's ugly, so what should i do?I will get the image resources vai angular scope, but I don't want a bad request first.

like image 222
Arnold Avatar asked May 22 '26 16:05

Arnold


1 Answers

Use the ngSrc directive which solves that problem.

like image 174
JB Nizet Avatar answered May 25 '26 05:05

JB Nizet