javascript – 在错误消息中访问ng-pattern

我有一个ng-repeat的属性列表,并希望显示每个输入的错误消息.对于模式错误,我还想显示它必须匹配的特定正则表达式.

我可以以某种方式访问​​输入的模式吗?我知道我可以添加一个包含正则表达式的属性,但我想知道是否有某种角度方式.

(这是一个过于简单的例子,不同属性的正则表达式可能不同)

<form name="form">
    <div data-ng-repeat="(attributeName, attributeMetaData) in configuration.metaData">

        <input data-ng-model="configuration[attributeName]" type="text" name="{{attributeName}}" data-ng-pattern="/^[0-9][0-9]:[0-9][0-9]$/">

        <span data-ng-show="form[attributeName].$error.pattern && form[attributeName].$dirty">
            Please check your input format [pattern should go here]
        </span>   
    </div>
</form>

jsFiddle:http://jsfiddle.net/lisapfisterer/ndu2g0ev/

最佳答案 根据您对模型无法更改的限制,我猜您最好的选择是使用包含正则表达式的单独模型

点赞