2017-02-16 83 views
0

我有一个AngularJS指令,创建一个Sparkline,然后我在一些模块中使用。该应用在Firefox(51 ..)中的行为与预期相同,但在Google Chrome浏览器(56 ..)中查看时,该应用无法提供所需的图形。奇怪的AngularJS 1.5行为嵌套指令中的Chrome组件

请注意,我已经从服务器测试了实际的应用程序,这不是一个Cross来源请求问题。此外,经检查,控制台上不会报告错误。

Image showing output in two browsers

这plunker再现了我原来的问题:https://plnkr.co/edit/K9wO5Ibx1Uk8ygkOUGU6?p=preview

感谢您的任何援助。

的index.html

<html> 
    <head> 
    <link rel="stylesheet" href="style.css" /> 
    <script src="jquery.min.js"></script> 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script> 
    <script src="jquery.sparkline.js"></script> 
    <script src="app.module.js"></script> 
    <script src="ab-help.module.js"></script> 
    <script src="ab-help.component.js"></script> 
    <script src="ab-spkline.directive.js"></script> 
    </head> 
<body ng-app="abMyapp"> 
    <h2>Testing sparkline directive via component in angular </h2> 
    <p>This is outside the ab-help tags</p> 
    <spk-line data="30, 1, 14, 10, 8, 15, 6, 13, 2"></spk-line> 
    <ab-help></ab-help> 
    </body> 
</html> 

各种的.js部分如下压缩:

// Define the 'app' module 
angular.module('abMyapp', ['abHelp']); //note in my original app more modules are injected here, example on plunker only shows one! 

// Define the `abHelp` module 
angular.module('abHelp', []); 

// Register `abHelp` component, along with its associated controller and template 
angular. 
module('abHelp'). 
component('abHelp', { 
    templateUrl: 'ab-help.template.html', 
    controller: function(){ 
     this.myData = "1, 1, 4, 14, 4, 15, 6, 23, 4"; 
    } 
}); 

//template 
<p>This is from inside component</p> 
<spk-line data="3, 1, 4, 10, 8, 5, 6, 3, 4"></spk-line> <br> 
<spk-line data="{{ $ctrl.myData }}"></spk-line> 

与感谢http://jsfiddle.net/NAA5G/当然http://omnipotent.net/jquery.sparkline/#s-about的所有重要迷你图指令,& JQuery,Angular!

angular.module('abMyapp').directive("spkLine", function() { 
    return { 
    restrict: "E", 
    scope: { 
     data: "@" 
    }, 

    compile: function(tElement, tAttrs, transclude) { 
     tElement.replaceWith("<span>" + tAttrs.data + "</span>"); 
     return function(scope, element, attrs) { 
     attrs.$observe("data", function(newValue) { 
      element.html(newValue); 
      element.sparkline('html', { 
      type: 'line' 
      }); 
     }); 
     }; 
    } 
    }; 
}); 

回答

1

实际上通过使用jquery sparkline的版本2.1.2进行排序。这有一个工具提示问题,我已经提出了issue #188

谢谢你看看。