Here is the problem :
This thing is turning me crazy since three days... I would like to use an angularJS variable as background image without using a directive.
My goal is to load any type of image (square, rectangle...etc), reduce it to match a 150px circle size (hidden what's too much) and center it into my page, without the image being squeezed (so keep the aspect ratio).
I'm using ionic 1.0, angular 1.6, so i tried to import this directive : https://www.npmjs.com/package/angular-background-image/v/0.1.2 but this doesn't work because of the "require" part.
I followed this angularjs: ng-src equivalent for background-image:url(...) but either this didn't work.
Here is the final solution :
Plunker : https://next.plnkr.co/edit/HMexvebJBXLg9Auu
// Here is the variable containing the image link
var app = angular.module('app', []);
app.controller("Ctrl",function($scope){
$scope.avatar = "https://i.ytimg.com/vi/7xWxpunlZ2w/maxresdefault.jpg";
});
#rounded-image {
border-radius: 50%;
width: 150px;
height: 150px;
background-size: cover;
background-repeat: no-repeat;
background-position: center;
overflow: hidden;
border: 3px solid red;
margin-left: auto;
margin-right: auto;
}
<script src="//unpkg.com/angular/angular.js"></script>
<body ng-app="app" ng-controller="Ctrl">
<div>
<div ng-style="{'background-image': 'url(' + avatar + ')'}" id="rounded-image"></div>
</div>
</body>