Reputation: 11388
I need ng-style to set the height of a div inside a resizable div.
This is the controller code that is executed :
$scope.uploadDropStyle = {
height: $scope.$parent.state.size.window.height - calculateDeduction()
};
$scope.$on("window:resize", function (event, width, height) {
$scope.uploadDropStyle.height = height - calculateDeduction();
});
Here is my link function :
link: function (scope, element, attributes, controller) {
var markup = '<div style="display:table"><form name="fieldEditor" class="entityEditor emailEditor">';
markup += <div class="fileTransferContainer" ng-style="{{uploadDropStyle}}"><br/><hr/>\
<few html removed here>
</div>\
</div>\
</div>';
element.html(markup);
$compile(element.contents())(scope);
}
}
Here is the DOM when I display my div
<div class="fileTransferContainer" style="height: 465px;" ng-style="{"height":465}">
When I resize my window, here is what I get :
<div class="fileTransferContainer" style="height: 465px;" ng-style="{"height":146}">
Why is there this "height: 465px;", and why is my ng-style not applied?
Upvotes: 0
Views: 593
Reputation: 6206
You should build you style variable as JSON
$scope.uploadDropStyle = {
"height": $scope.$parent.state.size.window.height - calculateDeduction() + "px"
};
I would extend my answer with recommending you to use a scope variable into the ng-style tag instead of a binded one:
markup += <div class="fileTransferContainer" ng-style="uploadDropStyle"><br/><hr/>\
Upvotes: 1