IE11 - 表单。$提交被设置为Angular按钮组件点击

时间:2016-10-06 20:04:56

标签: angularjs forms angularjs-directive

This plunker

我有Angular指令bl-button包裹'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"时才会设置$。

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

编辑:以下是我的指示:

.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);
          });
      };
    }
  };

});

1 个答案:

答案 0 :(得分:0)

我相信你会陷入this bug in AngularJS。解决方法,从那个bug:

  

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

请注意,这也列在Angular&#39; Internet Explorer Compatibility page