I'm having an issue (just learning Angular) with a string having any /
removed and replaced with =""
.
I have a directive that takes it's element and then wraps it with a div
and provides some styling to the div
- namely a background-url
- it is the URL that is being replaced with something else.
It may be a little odd - what I am actually trying to do here - and that's ok; i'm just trying to learn a little more about Angular and simple manipulation of elements seems a good place to tinker..
Here is what I have:
HTML - notice the set-background
attribute on the image.
<div id="home">
<img src="~/Content/Images/Site/home-background.jpg" set-background />
</div>
Angular directive
dwApp.directive('setBackground', function () {
return {
restrict: 'A',
scope: {},
link: function (scope, element, attrs) {
element.addClass('backgroundCover');
var bgImg = 'style="background-image:url("' + attrs.src + '");'
element.wrap('<div class="backgroundCoverContainer" ' + bgImg + '></div>');
element.remove();
}
}
});
Resulting HTML - notice the background-url
<div id="home">
<div class="backgroundCoverContainer" style="background-image:url(" content="" images="" site="" home-background.jpg");=""></div>
</div>
If I console.log(bgImg)
I get:
style="background-image:url("/Content/Images/Site/home-background.jpg");
Clearly, the background-image
isn't actually being rendered like that though...
any ideas?