如果未附加控制器名称,AngularJS指令不会更新模板

时间:2016-04-18 14:55:40

标签: angularjs directive

如果我在下面的代码中指定controller属性,那么我的代码将起作用。否则代码不会更新HTML模板:

function ngVisualizer($http, $timeout, SharedFactory, ThreejsFactory) {
    return {
        restrict: 'A',
        template: '<div id="canvas"></div>',
        transclude: 'true',
        priority: Number.MIN_SAFE_INTEGER, //Lowest priority
        link: function (scope, elem, attr, ctrl) {
            angular.element(document).ready(function () {
                var log = [];
                // play audio sound.
                var audio = new Audio('/Audio/Om_Sound.mp3');
                audio.loop = true;
                //audio.play();
                scope.$watch("fileData", function (newValue, oldValue) {
                    if (SharedFactory.getRefreshStatus()) {
                        scope.RemoveEntity();
                        scope.dateTime = 0;
                        debugger;
                        console.log(scope.fileData);

                        //ESTS service and service name created and added to scene.
                        var planetSize = scope.centralPlanetSize(scope.countOfMachines);
                        var centralPlanet = scope.drawCentralPlanet(planetSize, scope.getColor(scope.planetPressure, 100));
                        var centralPlanetText = scope.draw2DText(scope.sliceName, scope.destinationPoint, planetSize);
                        scope.sceneObject.add(centralPlanet);
                        scope.sceneObject.add(centralPlanetText);
                        //scope.nwScene.add(centralPlanet);
                        //scope.nwScene.add(centralPlanetText);
                        //scope.central = null;
                        angular.forEach(scope.fileData, function (value, key) {
                            try {
                                var sphere = new THREE.Mesh(scope.outerGeometry, scope.outerMaterial);
                                //line creation among services
                                var sourcePoint = new THREE.Vector3(scope.destinationPoint.x, scope.destinationPoint.y, scope.destinationPoint.z);
                                var destinationPoint = new THREE.Vector3(ThreejsFactory.getPlanetList()[key].x, ThreejsFactory.getPlanetList()[key].y, ThreejsFactory.getPlanetList()[key].z);
                                //var path = new THREE.LineCurve3(sourcePoint, destinationPoint);
                                var path = scope.getCurvePath(sourcePoint, destinationPoint);
                                //var hexColorValue = scope.getHexColorValue(value.MaxCount);
                                var tube = scope.drawPipe(path, scope.getColor(value.MaxCount, 65000));
                                //text for service name                            
                                var serviceTextGeometry = scope.draw2DText(value.ServiceName , ThreejsFactory.getPlanetList()[key], 40);
                                //scope.nwScene.add(serviceTextGeometry);
                                scope.sceneObject.add(serviceTextGeometry);
                                //sphere for service name
                                sphere.position.set(ThreejsFactory.getPlanetList()[key].x, ThreejsFactory.getPlanetList()[key].y, ThreejsFactory.getPlanetList()[key].z);
                                //scope.nwScene.add(tube);
                                scope.sceneObject.add(tube);
                                //scope.nwScene.add(sphere);
                                scope.sceneObject.add(sphere);                                
                                //from ests 
                                var toChild = scope.drawTorusIn(tube.geometry.parameters.path.v2, scope.pipeWidth, scope.getDonutFatness(value.DataBytesIn), "red");
                                //scope.nwScene.add(toChild);
                                scope.sceneObject.add(toChild);
                                //to ests 
                                var toParent = scope.drawTorusOut(tube.geometry.parameters.path.v1, scope.pipeWidth, scope.getDonutFatness(value.DataBytesOut), "blue");
                                //scope.nwScene.add(toParent);
                                scope.sceneObject.add(toParent);
                                scope.torusMovementPositive(tube, toParent, value.AvgSRTT);
                                scope.torusMovementNegative(tube, toChild, value.AvgSRTT);
                                //start
                                scope.addToServiceList(value, tube, sphere, serviceTextGeometry, toChild, toParent);
                            } catch (err) {
                                console.log(err);
                            }
                        }, log);
                        scope.nwScene.add(scope.sceneObject);
                    }
                });
            });
        }
        //,
        //controller: "LandingPageController"
    }
};

我无法弄清楚这个问题背后的根本原因。如果取消注释controller属性,则它开始工作,否则不会。

0 个答案:

没有答案