How to prevent view redraw when changing route in AngularJS

旧街凉风 提交于 2019-12-03 16:23:25

Addressing your "recalculate the entire map" question, one way to resolve this is to draw the Google Map at the same level as your ng-view, and shift it out of the view to hide it.

Here is a plunker illustrating how this would work:
http://plnkr.co/edit/wsjYoG2uXxYxXTmWdFGh?p=preview

Notice how I intentionally left a part of the map on screen when hiding to show that it does not redraw as you change the route.

You could create a dedicated service to store the data. As services are singleton, the data would be shared amongst your views and controllers. Something like this:

angular.module('myApp').factory('GlobalService', [
    function() {
        var _this = this;
        _this._data = {
            user: window.user,
            authenticated: !! window.user
        };

        return _this._data;
    }
]); 


angular.module('myApp').controller('FooController',
    ['$scope', 'GlobalService',
    function ($scope, GlobalService) {
    $scope.global = GlobalService;
    $scope.global.bar = someData;
    ...
]);

This looks like a useful read: AngularJS Performance Tuning for Long Lists. It details recommendations and pitfalls to avoid when rendering large/complex data structures.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!