加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

在IE 11上使用占位符文本时,Angular2设置为脏

发布时间:2020-12-17 17:10:02 所属栏目:安全 来源:网络整理
导读:我做了一些R关于这个问题,同样的问题也发生在Angular1上,大多数人建议使用ng-attr-placeholder,但Angular2中没有解决这个问题. 我问的是Angular2而不是Angular1. 解决方法 我找到了解决方案: 为占位符文本创建自定义指令 TS: import { Directive,ElementRe
我做了一些R&关于这个问题,同样的问题也发生在Angular1上,大多数人建议使用ng-attr-placeholder,但Angular2中没有解决这个问题.

我问的是Angular2而不是Angular1.

解决方法

我找到了解决方案:

为占位符文本创建自定义指令

TS:

import { Directive,ElementRef,Input } from '@angular/core';
import { NgControl } from "@angular/forms";
@Directive({
  selector: '[customPlaceholder]'
})
export class PlaceholderDirective {
  constructor(private el: ElementRef,private control : NgControl) { }
  @Input('customPlaceholder')
    public set defineInputType(pattern: string) {
        this.el.nativeElement.placeholder = pattern;
        setTimeout(() => {
            this.control.control.markAsPristine();
        },0);
    }
}

并在您的HTML中

HTML:

<textarea type="text" customPlaceholder="Message" class="form-control" formControlName="message" rows="10" >
</textarea>

问题是,它将设置< textbox>回到原始状态,用setTimeOut实现.但对于永久解决方案,角度团队应该调查它为什么IE设置< textbox>肮脏的.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读