angular.js - angular directive中調用highchart報錯
滿天的星座
滿天的星座 2017-05-15 16:55:01
0
2
616

在指令中掉用highchart報錯了245個錯,報錯內容是 illegal invocation 和 digest 循環達到上限,代碼如下

.directive('highchart',function($timeout){
    return{
        restrict:'E',
        template:'<p></p>',
        scope:{
            config:'='
        },
        link:function(scope, ele, attr) {
            var handle;
            scope.$watch('config',function(cfg){
                if(handle){
                    $timeout.cancel(handle);
                }
                handle = $timeout(function(){
                    console.log(ele.find('p'),scope.config)
                    ele.find('p').highcharts(scope.config)
                },250)
            })
        }
    }
})

我在chrome的控制台裡把log的變數呼叫是沒報錯的,highchart動作何處觸發了angular的循環

滿天的星座
滿天的星座

全部回覆(2)
巴扎黑

問題出在物件上,複製下物件就可以了

PHPzhong

我覺得應該是你link裡的scope.$watch()

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!