Understanding AngularJS ng-src

前端 未结 6 1966
猫巷女王i
猫巷女王i 2020-12-03 09:51

As explained here, the angularjs directive ng-src is used to prevent the browser from loading the resource (e.g. image) before the handlebars get parsed. I\'m currently usin

6条回答
  •  执笔经年
    2020-12-03 10:35

    Put the whole path inside the $scope variable. That way ng-src will wait until you provide it with the fully resolved path to the image:

    function MyCtrl($scope, $timeout) {
        var path = 'https://si0.twimg.com/profile_images/';
        $timeout(function () {
            $scope.path = path + '2149314222/square.png';
        }, 1000);
    };
    

    FIDDLE

提交回复
热议问题