Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Cannot read property 'setAttribute' of null when clicking on 'menu' when using data-ng-click="$mdOpenMenu()" #3258

Closed
DBassel opened this issue Jun 14, 2015 · 23 comments
Assignees
Labels
- Lots of Comments has: Pull Request A PR has been created to address this issue P4: minor Minor issues. May not be fixed without community contributions. resolution: fixed
Milestone

Comments

@DBassel
Copy link

DBassel commented Jun 14, 2015

TypeError: Cannot read property 'setAttribute' of null, when click event is marked by:
data-ng-click="$mdOpenMenu()"
when is marked:
ng-click="$mdOpenMenu()"
the issue disappears.

Thanks!

@Frank3K
Copy link
Contributor

Frank3K commented Jun 23, 2015

I don't think this issue is completely fixed, compared to what I expected earlier in #3252.

The file _menu.js contains the following references to ng-click only:

Lines 150-152

    if (!triggerElement.hasAttribute('ng-click')) {
      triggerElement = triggerElement.querySelector('[ng-click]');
    }

Lines 187-190:

  this.init = function(setMenuContainer) {
    menuContainer = setMenuContainer;
    triggerElement = $element[0].querySelector('[ng-click]');
  };

Can someone reopen this issue?

@amobiz
Copy link

amobiz commented Mar 3, 2016

Cannot read property 'setAttribute' of null

in material/src/components/menu/js/menuController.js

Lines 26-27:

triggerElement = $element[0].querySelector('[ng-click],[ng-mouseenter]');
triggerElement.setAttribute('aria-expanded', 'false');

Where triggerElement is null when there is no element with ng-click or ng-mouseenter attribute inside md-menu.

@cmacdonnacha
Copy link

+1

@ThomasBurleson ThomasBurleson modified the milestones: 1.1.0, 1.0-rc1 Mar 15, 2016
@ThomasBurleson ThomasBurleson added P0: critical Critical issues that must be addressed immediately. P4: minor Minor issues. May not be fixed without community contributions. and removed P0: critical Critical issues that must be addressed immediately. labels Mar 15, 2016
@homerjam
Copy link

+1

6 similar comments
@kaldebert
Copy link

+1

@ghost
Copy link

ghost commented May 2, 2016

+1

@jacobuk
Copy link

jacobuk commented May 6, 2016

+1

@manoharnv
Copy link

+1

@Karvel
Copy link

Karvel commented May 16, 2016

+1

@CanMehmetK
Copy link

+1

@ThomasBurleson ThomasBurleson modified the milestones: 1.1.0, Deprecated May 26, 2016
@farantesrodrigues
Copy link

ng-dblclick raises this error. ng-click does not.

@ghost
Copy link

ghost commented May 27, 2016

Can anyone help us , we stuck at below mentioned issue..thank you in advance

TypeError: Cannot read property 'setAttribute' of null at e.init

@devversion devversion self-assigned this May 27, 2016
@devversion devversion modified the milestones: - Backlog, Deprecated May 27, 2016
@devversion devversion added the has: Pull Request A PR has been created to address this issue label May 27, 2016
devversion added a commit to devversion/material that referenced this issue May 27, 2016
The service is containing the following features:
* Check for an element, to have the specified attribute, including the prefixes
* Generate an attribute selector for the specified attribute
* Build a list of all prefixed attributes

Fixes angular#3258. Fixes angular#8080. Closes angular#8121
@devversion
Copy link
Member

@Prajwal8 A pull request, which automatically adds the prefix is pending.

devversion added a commit to devversion/material that referenced this issue Jun 2, 2016
The service is containing the following features:
* Check for an element, to have the specified attribute, including the prefixes
* Generate an attribute selector for the specified attribute
* Build a list of all prefixed attributes

Fixes angular#3258. Fixes angular#8080. Closes angular#8121
@ghost
Copy link

ghost commented Aug 31, 2016

TypeError: Cannot read property 'setAttribute' of null at e.init...this issue did not solved yet, this is causing delay in completion of the project...Can anyone help us ??

@devversion
Copy link
Member

@Prajwal8 Did you properly create a menu with an element to open the menu (~ trigger element)

Also the new prefixer is available in the new v1.1.0 release.

@ghost
Copy link

ghost commented Aug 31, 2016

Ya...but am still facing this issue!

@ghost
Copy link

ghost commented Aug 31, 2016

@devversion am posting my code, write now i have hard coded the data...please do replay back

index.html

        <md-menu class="persondropdown">
                  <md-button href="" class="md-icon-button"
                           ng-click="headerObj.openMenu($mdOpenMenu, $event)"
                         aria-label="Personal Profile     Dropdown Menu">
             <span><img class="personimage" src="assets/images/person.png"></span> 
                    <span class="hidden-xs">{{loggedInUser}}</span> 
                    <span>
                  <md-icon md-font-icon="zmdi zmdi-caret-down"></md-icon>
                  <md-tooltip>Personal Profile</md-tooltip>
                  </span> 

        </md-button>
                <md-menu-content class="userflyout" width="4">
                  <md-subheader class="font-medium">Switch to:</md-subheader>
                  <md-menu-item>
                    <md-button ui-sref="home" aria-label="home"> <i class="profile-myprofile-icon"></i> 
                          home </md-button>
                  </md-menu-item>
                  <md-menu-item>
                    <md-button ui-sref="myprofile" aria-label="myprofile"> <i class="myprofile-icon"></i> myprofile </md-button>
                  </md-menu-item>
                  <md-menu-item>
                    <md-button ui-sref="date" aria-label="date"> <i class="profile-date-icon"></i> date </md-button>
                  </md-menu-item>

                  <md-menu-item>
                    <md-button ui-sref="changePassword" aria-label="Change Password"> 
                          Change Password   </md-button>
                  </md-menu-item>

                </md-menu-content>
              </md-menu>


ctrl.js

this.openMenu = function ($mdOpenMenu, ev) {

        $mdOpenMenu(ev);
    };

@ghost
Copy link

ghost commented Aug 31, 2016

index.html

     <md-menu class="persondropdown">
            <md-button href="" class="md-icon-button" ng-click="headerObj.openMenu($mdOpenMenu, $event)" aria-label="Personal Profile Dropdown Menu"> <span><img class="personimage" src="assets/images/person.png"></span> 
                <span class="hidden-xs">{{loggedInUser}}</span> 
                <span>
              <md-icon md-font-icon="zmdi zmdi-caret-down"></md-icon>
              <md-tooltip>Personal Profile</md-tooltip>
              </span> 

             </md-button>
            <md-menu-content class="userflyout" width="4">
              <md-subheader class="font-medium">Switch to:</md-subheader>
              <md-menu-item>
                <md-button ui-sref="home" aria-label="home"> <i class="profile-myprofile-icon"></i> home </md-button>
              </md-menu-item>
              <md-menu-item>
                <md-button ui-sref="myprofile" aria-label="myprofile"> <i class="myprofile-icon"></i> myprofile </md-button>
              </md-menu-item>
              <md-menu-item>
                <md-button ui-sref="date" aria-label="date"> <i class="profile-date-icon"></i> date </md-button>
              </md-menu-item>
              <md-divider></md-divider>
              <md-menu-item>
                <md-button ui-sref="account" aria-label="account"> account </md-button>
              </md-menu-item>
              <md-menu-item>
                <md-button ui-sref="changePassword" aria-label="Change Password"> Change Password </md-button>
              </md-menu-item>
              <md-menu-item>
                <md-button ng-click="headerObj.logOut()" aria-label="Sign out"> Sign out </md-button>
              </md-menu-item>
            </md-menu-content>
          </md-menu>

ctrl.js
this.openMenu = function ($mdOpenMenu, ev) {
originatorEv = ev;
$mdOpenMenu(ev);
};

@devversion
Copy link
Member

I cannot see any issues with that code. Tested in a codepen, and works like a charm without any errors.

http://codepen.io/DevVersion/pen/pEzxzG?editors=1000

@ghost
Copy link

ghost commented Aug 31, 2016

Thanks for the replay...am using the same code ,but some how am getting the error....please do suggest .what might possibly went wrong????

@devversion
Copy link
Member

As previous mentioned, I assume you still use an older version than v1.1.0.

Also this is not the right place to discuss those things - Questions like this are normally for the Angular Material Forum

@ghost
Copy link

ghost commented Aug 31, 2016

Thank you...

@rlaphoenix
Copy link

Just feed it ng-click="null" aswell as your custom way to open the menu (ng-right-click e.t.c). It will not do any errors, and will work. 👍

@Splaktar Splaktar modified the milestones: - Backlog, 1.1.0 Jul 19, 2018
@angular angular locked as resolved and limited conversation to collaborators Jul 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
- Lots of Comments has: Pull Request A PR has been created to address this issue P4: minor Minor issues. May not be fixed without community contributions. resolution: fixed
Projects
None yet
Development

Successfully merging a pull request may close this issue.