Angular ng-class performance issue when too many elements in DOM

后端 未结 2 374
萌比男神i
萌比男神i 2020-12-19 04:29

I have been working on a complex angular page which has been causing performance issue. To highlight the problem I have created a fiddle http://jsfiddle.net/4ex2xgL1/3/ here

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-19 05:23

    Finally I found the solution and it will helps lot to improve performance in angular js.

    If your model changes dynamically and if you have lots of data and then also it improve AngularJS pages rendering up to 1000% and more - no kidding !.

    Fore more information you can visit : http://orangevolt.blogspot.in/2013/08/superspeed-your-angularjs-apps.html

    Follow the steps:

    1. download the library from the link:library

    2.example without library:(check your console)

    function MyController( $scope) {
        var entries = [ 
            { label : 'one', value : 'first entry'}, 
            { label : 'two', value : 'second entry'}, 
            { label : 'three', value : 'third entry'}
        ];
        
        $scope.label ="";
        $scope.value ="";
        $scope.order = 'label';
        
        $scope.add = function() {
            entries.push({ 
                label : $scope.label, 
                value : $scope.value
            });
        };
            
        $scope.getEntries = function() {
            console && console.log( "getEntries() called");
            return entries;
        };
    }
    
    
    
    
    
    Label/Value :
    Entries sorted by
    {{entry.label}} = "{{entry.value}}"

    3.example with library:(check your console)

    function MyController( $scope) {
        var entries = [ 
            { label : 'one', value : 'first entry'}, 
            { label : 'two', value : 'second entry'}, 
            { label : 'three', value : 'third entry'}
        ];
        
        $scope.label ="";
        $scope.value ="";
        $scope.order = 'label';
        
        $scope.add = function() {
            entries.push({ 
                label : $scope.label, 
                value : $scope.value
            });
                // clear cache
            $scope.getEntries.cache = {};
        };
            
        $scope.getEntries = _.memoize( 
            function() {
                console && console.log( "getEntries() sorted by '" + $scope.order + " 'called");
                    // return entries sorted by value of $scope.order
                return _.sortBy( entries, $scope.order);
            }, 
            function() { 
                    // return the cache key for the current result to store 
                return $scope.order;
            }
        );
    }
    
    
    
    
    
    Label/Value :
    Entries sorted by
    {{entry.label}} = "{{entry.value}}"

提交回复
热议问题