在初始化之前无法在工具提示上调用方法;试图调用方法'隐藏'或'显示'

时间:2018-06-07 20:24:27

标签: javascript jquery angularjs jquery-ui-tooltip

嗨,我是angularjs的新手。我试图以角度显示/隐藏工具提示,但它给出了一些错误,说在初始化之前不能在工具提示上调用方法;试图调用方法'hide'或'show'

  

未捕获错误:无法在工具提示之前调用方法   初始化;试图调用方法'show'       在Function.error(jquery.js:250)       在HTMLImageElement.eval(eval at globalEval(jquery.js:328),:5:6122)       在Function.each(jquery.js:374)       在n.fn.init.each(jquery.js:139)       at n.fn.init.t.fn。(匿名函数)[as tooltip](eval at globalEval   (http://localhost:9000/bower_components/jquery/dist/jquery.min.js:2:2538),   :5:5897)       在HTMLImageElement。 (操作-controller.js:20089)       在HTMLImageElement.handle(jquery.js:4760)       在HTMLImageElement.dispatch(jquery.js:4430)       在HTMLImageElement.r.handle(jquery.js:4116)

     

未捕获错误:无法在工具提示之前调用方法   初始化;试图调用方法'隐藏'       在Function.error(jquery.js:250)       在HTMLImageElement.eval(eval at globalEval(jquery.js:328),:5:6122)       在Function.each(jquery.js:374)       在n.fn.init.each(jquery.js:139)       at n.fn.init.t.fn。(匿名函数)[as tooltip](eval at globalEval   (http://localhost:9000/bower_components/jquery/dist/jquery.min.js:2:2538),   :5:5897)       在HTMLImageElement。 (操作-controller.js:20094)       在HTMLImageElement.handle(jquery.js:4760)       在HTMLImageElement.dispatch(jquery.js:4430)       在HTMLImageElement.r.handle(jquery.js:4116)

下面的

是代码段:

controllers.directive('tooltip', function(){
    return {
        restrict: 'A',
        link: function(scope, element, attrs){
        element.hover(function(){

            console.log(element);
            console.log(attrs);
            console.log($(this).attr('title'));
           // $(this).attr('title',"dummy");

            let turbineCountNumber = $(this).attr('title');

            let dynamicManufacturer = $('select#manufacturer'+turbineCountNumber + ' option:selected').text().trim();
            let dynamicPowerCourve = $('select#powerCurve'+turbineCountNumber + ' option:selected').text().trim();
            let dynamicHubHeight = $('select#hubHeight'+turbineCountNumber + ' option:selected').text().trim();
            let dynamicTipHeight= $('#tipHeight'+turbineCountNumber).val().trim();
            let dynamicPvalue = $('select#pvalue'+turbineCountNumber + ' option:selected').text().trim();
            let dynamicUncertainty = $('#uncertailty'+turbineCountNumber).val().trim();


            $(this).attr('title',"OEM : " + dynamicManufacturer +"\n" + "POWER CURVE :" + dynamicPowerCourve+
                        "\n" + "Hub Height : " + dynamicHubHeight + "\n" +  "Tip Height : " + dynamicTipHeight+
                        "\n" + "P-Value : " + dynamicPvalue + "\n" + "dynamicUncertainty :" + dynamicUncertainty);
            $(this).tooltip('show');
            // on mouseenter
            //element.tooltip('show');
        }, function(){
            // on mouseleave
            $(this).tooltip('hide');
            //element.tooltip('hide');
        });
    }
};
});

0 个答案:

没有答案