【问题标题】:AngularJS how to pass event from ng-really clickAngularJS如何从ng-really click传递事件
【发布时间】:2014-07-27 09:38:25
【问题描述】:

我想将事件传递给我的方法,但它像“未定义”一样到达。这是我的态度

  <button class="btn btn-danger" ng-really-message="Are you sure want to delete?"
         ng-really-click="uc.deleteUser(user.id)">
         <i class="glyphicon glyphicon-trash"></i> </button>

我在 .coffee 文件中的方法

    deleteProduct: (id, event) ->
       console.log(event)
       @ProductService.deleteProduct(id)
       .then(
           (data) =>
               @getAllProducts()
           ,
           (error) =>
               @$log.error "Unable to delete Products: #{error}"
           )

但是,如果我通过 ng-click 传递事件,它可以正常工作。根据'ng-really click' $event 神奇地消失了!!!请帮帮我。

【问题讨论】:

    标签: html angularjs coffeescript


    【解决方案1】:

    这里是支持传递$event的版本:

    app.directive('ngReallyClick', ['$parse',
      function($parse) {
        return {
          compile: function(tElement, tAttrs) {
            var fn = $parse(tAttrs.ngReallyClick);
            return function(scope, element, attrs) {
              element.on('click', function(event) {
                var message = attrs.ngReallyMessage;
                if (message && confirm(message)) {
                  scope.$apply(function() {
                    fn(scope, {
                      $event: event
                    });
                  });
                }
              });
            };
          }
        };
      }
    ]);
    

    用法:

    ng-really-click="uc.deleteUser(user.id, $event)"
    

    【讨论】:

      猜你喜欢
      • 2015-05-19
      • 1970-01-01
      • 1970-01-01
      • 2016-04-16
      • 2013-10-21
      • 1970-01-01
      • 2017-02-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多