Reputation: 222722
I have a widget which is attached to a resizable directive, i have a highchart placed inside this directive and want to get this chart resized whenever the container is resized. It works well, but when i am using the same directive for different charts, i need to pass the widget id inside the directive.
HTML:
<div ng-controller="CustomWidgetCtrl" plumb-item class="item" style=" top: 50px; left: 110px; height: 500px; width: 500px; " ng-repeat="widget in dashboard.widgets" ng-style="{ 'left':widget.sizeX, 'top':widget.sizeY }"
data-identifier="{{widget.id}}" resizeable ng-click="resize(widget) >
<div ng-if="widget.type === 'All'" class="box" >
<div class="box-header" >
<div class="box-header-btns pull-right" style="top:10px" >
<a title="Data" ng-click="toggleModal(widget)" class="glyphicon glyphicon-list-alt"></i><a>
<a title="settings" ng-click="openSettings(widget)"><i class="glyphicon glyphicon-cog"></i></a>
<a title="Remove widget" ng-click="remove(widget)"><i class="glyphicon glyphicon-trash"></i></a>
</div>
</div>
<div ng-controller="highchartCtrl">
<highchart id="widget.id" config="widget.chartConfig" ></highchart>
</div>
</div>
</div>
</div>
Directive :
routerApp.directive('resizeable', function() {
return {
restrict: 'A',
link: function(scope, element, attrs) {
$(element).resizable({
resize: function(event, ui) {
var chart = $('#chart1').highcharts();
height = ui.size.height - 100;
width = ui.size.width - 40;
chart.setSize(width, height, doAnimation = true);
jsPlumb.repaint(ui.helper);
},
handles: "all"
});
}
};
});
Upvotes: 0
Views: 264
Reputation: 4713
identifierchange your HTML to following
<div ng-controller="CustomWidgetCtrl" plumb-item class="item" style=" top: 50px; left: 110px; height: 500px; width: 500px; " ng-repeat="widget in dashboard.widgets" ng-style="{ 'left':widget.sizeX, 'top':widget.sizeY }"
data-identifier="{{widget.id}}" resizeable ng-click="resize(widget) >
...
...
And you directive to following
routerApp.directive('resizeable', function() {
return {
restrict: 'A',
link: function(scope, element, attrs) {
var widgetId = attrs.identifier;
...
...
Upvotes: 1