【问题标题】:IE11 - form.$submitted being set wronly on Angular button-component clickIE11 - form.$submitted 在 Angular 按钮组件单击时被错误设置
【发布时间】:2016-10-06 20:04:55
【问题描述】:

This plunker

我有包装“按钮”元素的 Angular 指令 bl-button,我正在通过 my-type 设置按钮的 type 属性和 my-click 函数来运行某些东西。

我的问题是,仅在 IE11 中,即使我通过 my-type.. 传递“按钮”,父表单的 $submitted 标志也会被设置?

  <bl-button my-click="myJob(myform)" my-type="button">Save2</bl-button>

在 Chrome 或 FF 中,正如预期的那样,仅当我说 my-type="submit" 时才设置 $submitted。

我可能在这里遗漏了一些东西。

编辑:下面是我的指令:

.directive('blButton', function () {
  return {
    restrict: 'E',
    transclude: true,
    scope: {
      myClick: '&', // myClick() returns promise
      myType: '@' // by default 'button'
    },
    template: '<button type="{{myType1}}" ng-click="click()" ng-transclude></button>',
    link: function (scope, elem, attrs) {

      scope.myType1 = scope.myType || 'button';

      scope.click = function () {
        scope.myClick()
          .then(function(data) {
            console.log('resolved:', data);
          }, function(data) {
            console.log('rejected:', data);
          });
      };
    }
  };

});

【问题讨论】:

  • 请将所有相关代码作为minimal reproducible example 包含在问题本身中,而不是在第三方网站上。
  • @Mike,编辑显示指令代码,如果您有兴趣,也可以 fork 我的 plunker 并提出解决方案。谢谢。

标签: angularjs forms angularjs-directive


【解决方案1】:

我相信你会爱上this bug in AngularJS。解决方法,来自那个错误:

解决方法:使用ng-attr-type="{{someInterpolatedThing}}" 修复它。

请注意,这也列在 Angular 的 Internet Explorer Compatibility page 中。

【讨论】:

  • 这解决了我在 IE11 上使用 Angular1.4.2 的问题。这些链接也很有帮助。非常感谢。
猜你喜欢
  • 1970-01-01
  • 2019-09-01
  • 2016-02-17
  • 1970-01-01
  • 2023-03-13
  • 2020-03-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多