如何在typescript .ts文件中获取ngcontrol的占位符属性值

时间:2016-10-06 05:26:45

标签: angular typescript


我在placecript .ts文件中将占位符属性设置为未定义。 这是我写的代码 -

HTML代码 -

<label class="lab1">Closing date</label>
<input placeholder="M/d/yyyy" type="text" [(ngModel)]="_module.ClosingDate" ngControl="ClosingDate" #ClosingDate="ngForm">
<button type="submit" class="custombutton" (click)="Test1(ClosingDate)">Get Placeholder value</button>

打字稿文件代码 -

function Test1() {
    var i;
    for (i = 0; i < arguments.length; i++) {
        alert(arguments[i].name); //here i got correct thing i.e.- "ClosingDate"
        alert(arguments[i].placeholder); //here i'm expecting - "M/d/yyyy" but i got wrong value - "undefined"
    }
}

当我点击我的按钮时,它会调用方法Test1(),参数为#34; ClosingDate&#34;这是我的ngcontrol的名字。我通过参数在Test1()方法中找到了ngco​​ntrol的名称,但是当我想要在警告窗口中占位符的值时,我得到了&#34; undefined&#34;代替&#34; M / d / yyyy&#34;。

我在.ts文件中编写的代码使用html输入控件成功运行,但是当我使用ngcontrol然后它没有成功运行时,建议我,我如何获得占位符值。

感谢
Kapil Bhagwat

1 个答案:

答案 0 :(得分:0)

Intl.DateTimeFormat().resolvedOptions().timeZone
<label class="lab1">Closing date</label>
<input #myInput placeholder="M/d/yyyy" type="text" [(ngModel)]="_module.ClosingDate" ngControl="ClosingDate" #ClosingDate="ngForm">
<button type="submit" class="custombutton" (click)="Test1(ClosingDate, myInput.getAttribute('placeholder'))">Get Placeholder value</button>