Alexander Bondarenko
Alexander Bondarenko

Reputation: 207

Need help to add chart js to modal window

here is a diagram made by Chart

<div class="diagram">
<canvas id="pie" class="chart chart-pie" width="150" height="150" data="ModalObj.FunctionalTest" labels="labels" colours="Colours">
</canvas>

this is directive

.directive('modal', function () {
    return {
        template: '<ng-include src="getTemplateUrl()"/>',
        restrict: 'E',
        controller: function($scope) {
            //function used on the ng-include to resolve the template
            $scope.getTemplateUrl = function() {
                return $scope.path;
            }
        }
    }});

besides I have to add the diagram in a modal if template url needs it, not all templates use chart

Upvotes: 0

Views: 857

Answers (1)

softvar
softvar

Reputation: 18435

DEMO: http://jsfiddle.net/softvar/9cf47fe1/1/

HTML:

<div ng-app="myApp">
    <!-- Button trigger modal -->
    <button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
      Launch demo modal
    </button>

    <!-- Modal -->
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
      <div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title" id="myModalLabel">Modal title</h4>
          </div>
          <div class="modal-body">
              <elem-modal></elem-modal>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            <button type="button" class="btn btn-primary">Save changes</button>
          </div>
        </div>
      </div>
    </div>
</div>

JS:

var app = angular.module('myApp', []);
app.directive('elemModal', function () {
    return {
        template: '<p>Test</p><ng-include src="getTemplateUrl()"/>',
        restrict: 'E',
        controller: function($scope) {
            //function used on the ng-include to resolve the template
            $scope.getTemplateUrl = function() {
                return $scope.path;
            }
        },
        link: function (scope) {
            console.log(scope)
        }
    }});

Upvotes: 1

Related Questions