Exibir imagem em tamanho real em angular.js
Preciso exibir uma imagem em seu tamanho real, mesmo que seja maior que seu contêiner. Eu tentei o truque de usar variável de imagem ecapturando o tamanho na carga com algo parecido com isto:
HTML:
<div ng-controller="MyCtrl">
<input ng-model="imageurl" type="url" />
<button ng-click="loadimage()" type="button">Load Image</button>
<img ng-src="{{image.path}}"
style="width: {{image.width}}px; height: {{image.height}}px" />
</div>
Javascript:
.controller("MyCtrl", ["$scope", function ($scope) {
$scope.image = {
path: "",
width: 0,
height: 0
}
$scope.loadimage = function () {
var img = new Image();
img.onload = function () {
$scope.image.width = img.width;
$scope.image.height = img.height;
$scope.image.path = $scope.imageurl;
}
img.src = $scope.imageurl;
}
}]);
Este script funciona, mas somente depois que o botão é clicado várias vezes se a imagem for grande.
O que devo fazer para que funcione em um clique?
Existe uma maneira melhor de descobrir o tamanho da imagem do que isso?