AngularJS VS(AnguarJS + jQuery的)VS、AngularJS、jQuery、AnguarJS

2023-09-14 00:11:23 作者:残墨ヾ断诗

我有一个关于性能的问题,当你仅使用纯JavaScript AngularJS,当你使用AngularJS使用jQuery。

例如:

  app.directive('fitHeight',函数($窗口){    返回{        限制:'A',        链接:功能(S){            s.contentminHeight = $ window.innerHeight  -  40 +'像素';            VAR H = $ window.innerHeight;            $(窗口).resize(函数(){                如果(H!== $ window.innerHeight){                    H = $ window.innerHeight;                    s.contentminHeight =(H  -  40)+'像素';                    S $适用();                }            });        }    };}); 

我看到了与$窗口AngularJS验证调整大小的德precated等选项是创建一个间隔来检查,我发现jquery.resize更易于接受。

  app.directive('leftmenuDropdown',函数(){    返回{        限制:'C',        链接:功能(S,E){            e.click(函数(){                变种M = $(e.parent()找到(UL)[0]);                如果(m.hasClass('DD-开')){m.removeClass('DD-开')}其他{m.addClass('DD-开')}            });        }    };}); 
5个最佳 Python IDE 和文本编辑器

我在谷歌搜索,我理解为.hasClass比纯JavaScript更最快的。

关于性能,我应该怎么办呢?为了保持与jQuery的或AngularJS只使用AngularJS用纯JS?

解决方案   

Angularjs自带jqLit​​e

您可以有许多几乎需要的功能在里面,剩下的我也创建与jQuery +角申请,并得到了冲突,多次应用走出角的范围之内。   

角广为流行

您会发现它支持这样你得到的jQuery,你可以用角(jqLit​​e)自行启动。   

效果

当然装载两个重库/框架和保持其平衡将花费你更多。

I have a question about performance when you use only AngularJS with pure JavaScript and when you use AngularJS with jQuery.

ex:

app.directive('fitHeight', function($window) {
    return {
        restrict: 'A',
        link: function(s){
            s.contentminHeight = $window.innerHeight - 40 + 'px';
            var h = $window.innerHeight;
            $(window).resize(function() {
                if ( h !== $window.innerHeight ) {
                    h = $window.innerHeight;   
                    s.contentminHeight = ( h - 40 ) + 'px';
                    s.$apply();
                }
            });
        }
    };
});

I saw as the verification with AngularJS of $window resizes is deprecated, and other options was to create a Interval to check, I found jquery.resize more acceptable.

or

app.directive('leftmenuDropdown', function() {
    return {
        restrict: 'C',
        link: function(s, e){    
            e.click(function(){
                var m = $(e.parent().find("ul")[0]);
                if ( m.hasClass('dd-open') ) { m.removeClass('dd-open') } else { m.addClass('dd-open') }
            });
        }
    };
});

I search on google and I understood as .hasClass is more fastest than pure JavaScript.

About performance, what I should do? To keep jQuery with AngularJS or to use only AngularJS with pure JS?

解决方案

Angularjs comes with jqLite

You can have almost many needed functionalities in it, rest I did create an application with jQuery+Angular and got conflicts many times as the app get out of angular's scope.

Angular is widely popular

You will find support for it such you get for jQuery, you can start with angular(jqLite) itself.

Performance

of course loading two heavy libraries/framework and maintaining their equilibrium will cost you more.