zachfitz/Ionic-Material

Why manipulate DOM from controllers?

Closed this issue · 0 comments

I've been working with AngularJS for the past 2 years and just now got interested in ionicframework and specially with this project.

However, my understanding of the good practices are to never manipulate DOM in services or controllers, and that's just what demo does.

Explicity

var navIcons = document.getElementsByClassName('ion-navicon');
    for (var i = 0; i < navIcons.length; i++) {
        navIcons.addEventListener('click', function() {
            this.classList.toggle('active');
        });
    }

$scope.hideNavBar = function() {
        document.getElementsByTagName('ion-nav-bar')[0].style.display = 'none';
    };

    $scope.showNavBar = function() {
        document.getElementsByTagName('ion-nav-bar')[0].style.display = 'block';
    };

    $scope.noHeader = function() {
        var content = document.getElementsByTagName('ion-content');
        for (var i = 0; i < content.length; i++) {
            if (content[i].classList.contains('has-header')) {
                content[i].classList.toggle('has-header');
            }
        }
    };

Implicity

$timeout(function() {
        ionicMaterialMotion.fadeSlideIn({
            selector: '.animate-fade-slide-in .item'
        });
    }, 200);

As my ionic knowledge is limited, is there a reason not to write those things using directives?