material icon indicating copy to clipboard operation
material copied to clipboard

<md-button> ng-click fires inconsistently with Ionic Framework/ng-Material latest versions

Open bradmartin opened this issue 11 years ago • 39 comments

http://codepen.io/anon/pen/MYOeap

The plunker above works fine, I found this on the Ionic Framework forums and it's functional and the click is fired as expected.

However the same code with the latest ionic css/js files along with latest Angular Material via bower install, the click doesn't work as intended. Any reason? I've also installed the #master but the clicks on md-button still don't work very well. It may fire once every 10-20 clicks, and sometimes it fires once every 5 clicks. This is a hangup for me right now on moving forward with a project.

bradmartin avatar Feb 05 '15 22:02 bradmartin

@bradmartin for us it was a trivial issue, we were including the libraries by using //cdn/ url refferals, once we used web normalized 'http://cdn" addressing it was all ok. Are you using a call to a modal for the login, or a controller? It may not be directly related to material, or just expected behavior.

rlucian avatar Mar 18 '15 14:03 rlucian

The current master has improved the use of ng-click events within the Chrome mobile emulator (don't have a charged device right now to test).

   <section layout="row" layout-align="center center">
                    <md-button nav-clear flex ng-click="Login()" class="md-raised md-primary">Login</md-button>
                </section>
                <br />
                <br />
                <br />
                <p flex layout="row" layout-align="center center">
                    Don't have an account?
                </p>
                <section layout="row" layout-align="center center">
                    <md-button class="primary" flex md-no-ink href="#/register">Sign Up</md-button>
                </section>
                <br />
                <br />
                <br />
                <div layout="row" layout-align="center center">
                    <md-button flex md-no-ink href="#/forgotpassword">Forgot password?</md-button>
                </div>

In the markup above, the LOGIN button is working fine, just not the with as anchors.

bradmartin avatar Mar 20 '15 03:03 bradmartin

any more information on this?

stellasoft-will avatar Apr 13 '15 14:04 stellasoft-will

If you search through the issues you will see a few other related issues to gestures and events. I think they are all planned for the 0.9.0 release.

bradmartin avatar Apr 13 '15 14:04 bradmartin

Just tried out the master version : v0.8.3-master-1cd1d69

fires click events properly, however not when used with href property.

In the snippet below the Login works, the SIGN UP and Forgot Password do not. Was the href property dropped from support on ? I think in the demos in previous versions this was acceptable but I could be mistaken.

    <ion-view title="" hide-nav-bar="true">
        <ion-content>
                <form name="loginform" layout="row" layout-sm="column" novalidate>
                    <md-input-container flex>
                        <label>Username or Email</label>
                        <input ng-model="user.username" type="text">
                    </md-input-container>
                    <md-input-container flex>
                        <label>Password</label>
                        <input ng-model="user.password" type="password">
                    </md-input-container>
                </form>
                <section layout="row" layout-align="center center">
                    <md-button nav-clear flex ng-click="Login()" class="md-raised md-primary">Login</md-button>
                </section>
                <p flex layout="row" layout-align="center center">
                    Don't have an account?
                </p>
                <section layout="row" layout-align="center center">
                    <md-button class="primary" flex md-no-ink href="#/register">Sign Up</md-button>
                </section>
                <div layout="row" layout-align="center center">
                    <md-button flex md-no-ink href="#/forgotpassword">Forgot password?</md-button>
                </div>
            </md-content>
        </ion-content>
    </ion-view>

bradmartin avatar Apr 13 '15 18:04 bradmartin

For Ionic-Angular Material mobile solutions that using jQuery, you can now disable Material click hijacking by using $mdGestureProvider in

   app = angular.module('MyApp', ['ngMaterial'])
      .config(function( $mdGestureProvider ) {
          $mdGestureProvider.skipClickHijack();
      });

This will configure the $mdGesture service to not intercept clicks (stop propagation and prevent defaults).

ThomasBurleson avatar Apr 13 '15 18:04 ThomasBurleson

Works perfectly for my case. Thanks!

bradmartin avatar Apr 13 '15 18:04 bradmartin

I tried using this and my Ionic Cordova App fails because Angular is throwing me an error:

Uncaught ReferenceError: jQuery is not defined 

I had to do some code changes to make it work without an error.

Before:

    var self = {
      handler: addHandler,
      register: register,
      // On mobile w/out jQuery, we normally intercept clicks. Should we skip that?
      isHijackingClicks: (isIos || isAndroid) && !JQuery && !forceSkipClickHijack
    };

After:

var hasJQuery =  typeof jQuery !== 'undefined' && angular.element === jQuery;

    var self = {
      handler: addHandler,
      register: register,
      // On mobile w/out jQuery, we normally intercept clicks. Should we skip that?
      isHijackingClicks: (isIos || isAndroid) && !hasJQuery && !forceSkipClickHijack
    };

sebmaniac avatar May 12 '15 18:05 sebmaniac

@sebmaniac - great catch. This should be improved with the commit SHA https://github.com/angular/material/commit/a22f6817fb6e89f7004d91bc8ba895b860ea8578

ThomasBurleson avatar May 12 '15 20:05 ThomasBurleson

thank you @ThomasBurleson,

$mdGestureProvider.skipClickHijack(); trick works perfectly for me

ashishtilara avatar Jun 13 '15 07:06 ashishtilara

@ThomasBurleson FYI, this is happening again to Material v1.0.0 onwards. However, the solution $mdGestureProvider.skipClickHijack();

works nicely.

yxh10 avatar Feb 24 '16 01:02 yxh10

@ThomasBurleson thanks for your solution. it Works perfectly. Great

ikhsanputra07 avatar Apr 14 '16 02:04 ikhsanputra07

" $mdGestureProvider.skipClickHijack(); " Where to write it? @ThomasBurleson ,

ilkayhan avatar Apr 26 '17 06:04 ilkayhan

@ilkayhan first import angular-material to get $mdGestureProvider, then do it in app.config.

thomcom avatar Jun 07 '17 20:06 thomcom

Could there be a similar issue with the blur event firing when it is not necessary ? (Using along ionic-v1)

daweedm avatar Jun 14 '17 05:06 daweedm

@ilkayhan - try

myAppModule.config(function($mdGestureProvider) {
    $mdGestureProvider.skipClickHijack();
});

ThomasBurleson avatar Jun 14 '17 13:06 ThomasBurleson

@jonathan68 you are using AngularJS Material with Ionic 2 or Angular Material with Ionic 2? For Angular Material, you can ask questions in their forums.

Splaktar avatar Jan 17 '18 08:01 Splaktar

@ThomasBurleson can you say more about where

myAppModule.config(function($mdGestureProvider) { $mdGestureProvider.skipClickHijack(); });

goes? I tried it in my main.js file but that didn't seem to work, do I need to import angular-material like @thomcom said?

sas1018 avatar Jun 11 '18 12:06 sas1018

@sas1018 what exactly happened when you say "didn't seem to work"? The relevant docs can be found here: https://material.angularjs.org/latest/api/service/$mdGestureProvider

Splaktar avatar Jun 11 '18 18:06 Splaktar