【发布时间】:2016-10-06 20:04:55
【问题描述】:
我有包装“按钮”元素的 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