即使在输入值之后,Angular 2文本框还需要验证消息

问题描述:

我的要求

我需要在输入值后隐藏文本框中所需的错误消息

I need to hide the error message of required from the text box after the value has been entered

我做了什么

我创建了一个表单,用户可以在其中添加动态字段点击添加按钮,因为会有文本框,点击该文本框我会显示一个模态,在用户输入模式中的值后,它会有一些字段,他们会点击一个按钮模态将获得值并将其显示在模态页脚内的预标签中,使用jquery从前标签获取文本并将文本应用于按钮上的文本框字段单击模态页脚

I have created a form in which user can add dynamic fields by clicking add button, in that there will be text box, on click of that text box am showing out a modal in which it will have the some couple of fields after the user entered the fields with value in the modal they will hit a button in the modal will be getting value and displaying it in a pre tag inside the modal footer, using jquery am getting the text from the pre tag and applying the text to the text box fields on the button clicks inside the modal footer

问题

即使在使用jquery从pre标签粘贴值之后仍然会得到错误消息如何摆脱它

Even after the value is pasted from the pre tag using jquery still am getting the erro message how to get rid of it

这是我的代码供您参考

  <input ngControl="rules" id="rule_{{i}}" class="form-control rulez" #rules="ngForm" data-toggle="modal" data-target="#myModal" type="text" style="width: 299px !important;">

        <div class="error" *ngIf="rules.control.touched">
            <div *ngIf="rules.control.hasError('required')">Please Select a Rule</div>
        </div>
</div>

 <pre id="preTag"></pre>

Jquery代码从模态中获取值并在模式弹出时将其应用于同一文本框by onclick

Jquery code to get value from the modal and applying it to the same text box when the modal popped up by onclick

var idz, valz;
$(document).ready(function () {
    $(document).delegate('#getRuleStr', 'click', function () {
        console.log("hey"+idz);
        $('#'+idz).val($('#preTag').text());
    });
    $(document).delegate('.rulez', 'click', function () {
        idz = this.id;
        valz = $('#' + idz).val();
        console.log("inn" + valz);

            $('#builder').queryBuilder('reset');
            $('#resultRule').addClass('hide').find('pre').empty();

    });
});

请帮我解决此问题

据我所知,在修改值后,需要在输入上发出更改事件,以使Angular2 Forms更新其状态。

As far as I know you need to emit the change event on the input after modifying the value to make Angular2 Forms update its state.

在Angular2中,通常更好的是更新模型并从视图绑定到它以更新视图以反映Angular2的模型,而不是直接搞乱DOM使用jQuery。

In Angular2 it's usually better to update the model and bind to it from the view to get the view updated to reflect the model by Angular2, instead of messing with the DOM directly using jQuery.