Angular Material sidenav event broadcasted

2019-07-20 07:19发布

问题:

I'm using sidenav directive from Angular Material. When we click out of the component, sidenav will be closed. What is the event broadcasted at that time?

回答1:

In your controller use $watch to check the return value of isOpen():

  $scope.$watch(
    function () {
      return $mdSidenav('left').isOpen();
    },
    function (newValue, oldValue) {
      console.log(newValue);
      if (newValue == false) {
        var button = angular.element(document.querySelector('#navButton'))
        button.removeAttr('md-focused')
      }
    });


回答2:

If you look at the directive there is a function to detect,

self.close  = function() { return self.$toggleOpen( false ); };

Here is the SideNav directive