简体   繁体   中英

angularjs with svg image template

I use AngularJs v1.6.10 My html view contains code:

<script type="text/ng-template" id="animation_item_renderer.html">
<g opacity="1">
    <g ng-repeat="ctrl in control.controls">
        <g>
            <g>
                <image id="{{ctrl.id}}" xlink:href="{{ctrl.imageSource}}"
                       animation-size-item item-width="ctrl.width"
                       item-height="ctrl.height"
                       ng-if="ctrl.getType()===2">
                </image>
                <rect id="{{ctrl.id}}" fill="{{ctrl.color}}" width="150"
                      height="20" ng-if="ctrl.getType()===1">
                </rect>
            </g>
        </g>
    </g>        
    <g ng-repeat="control in control.children" opacity="1" 
       ng-include="'animation_item_renderer.html'">
    </g>
</g>

<svg xmlns='http://www.w3.org/2000/svg' preserveAspectRatio="xMinYMin meet" viewBox="0,0,1000,700" style="background-color: ivory;font-size: 32px">
<g ng-repeat="control in vm.controls" ng-include="'animation_item_renderer.html'">

</g>

When ctrl.getType()===2 in browser displays next code:

<g>

    <!-- ngIf: ctrl.getType()===2 -->
    <!-- end ngIf: ctrl.getType()===2 -->
    <!-- ngIf: ctrl.getType()===1 -->
</g>

and image not displayed.
Has anyone encountered a similar problem?

I solved this problem with custom directive

directive("svgImage", [function() {
        return {
            restrict: 'E',
            replace: true,
            scope: {
                xAxis: '=',
                yAxis: '=',
                imgHeight: '=',
                imgWidth: '=',
                imgSrc:'='
            },
            template:
                '<image xlink:href="{{imgSrc}}" ng-attr-x="{{xAxis}}" ng-attr-y="{{yAxis}}" ng-attr-height="{{imgHeight}}" ng-attr-width="{{imgWidth}}"></rect>',
            templateNamespace: 'svg'
        };
    }]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM