0

我正在尝试在我的 ng-include 文件中使用“minisCtrlOverall”控制器,但除非我将 ng-controller 放入实际的overall.html 文件中,否则我的控制器中的任何功能都不适用于包含的文件。我想做的是从我的控制器访问我的overall.html文件中的“ring-fill”类。我想在所有“环填充”中添加“活动”类,但它不起作用。我猜这不起作用,因为包含的文件是在控制器运行之后出现的?有谁知道我该如何解决这个问题?

控制器:

angular.module('ciscoImaDashboardAdmin',[])
.controller('minisCtrlOverall', function ($scope, $rootScope, dummyData) {
    $scope.overallOn = true;

    $scope.switchView = function(element) {
        var value = element.target.attributes['value'].value;

        if(value == "overall") {
            $scope.overallOn = true;
            $scope.swimlaneOn = false;
        }
        else if(value == "swimlane") {
            $scope.swimlaneOn = true;
            $scope.overallOn = false;
        }
    };


    var totalRings = 9;
    var maxScore = 10;

    var data_overall = {
        average_score:  6
    }

    var ringToHighlight = Math.floor((data_overall.average_score/maxScore)*totalRings); //round down

    var i = 0;
    var rings = [];
    var ringClass = 'path.ring-fill:not(.ring-border)';

    $(ringClass).each(function(){
        rings.push($(this)[0]);
    });

    while( i < ringToHighlight) {
        fillPath(i);
        i = i + 1;
    }



    function fillPath(i) {
        if(i < ringToHighlight) {
            var selectedRing = $(rings[i]);
            selectedRing.attr("class", "ring-fill active");
        }
    }

});

HTML:

<div class="row mini" ng-show="overallOn" ng-controller="minisCtrlOverall">
   <div class="col-sm-3">
     <div ng-include="'svgs/overall.html'"></div>
   </div>
</div>
4

0 回答 0