Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Validation 如何退出angular2字段验证模式_Validation_Angular - Fatal编程技术网

Validation 如何退出angular2字段验证模式

Validation 如何退出angular2字段验证模式,validation,angular,Validation,Angular,如何以angular2形式放置模式正则表达式 我有这个图案 @Component({ selector: 'my-form', template: ` <h2>My Form</h2> <form (ngSubmit)="onSubmit(ff)" #ff="ngForm"> <div> <label for="mail">Field

如何以angular2形式放置模式正则表达式 我有这个图案

@Component({
    selector: 'my-form',
    template: `
        <h2>My Form</h2>
        <form (ngSubmit)="onSubmit(ff)" #ff="ngForm">
            <div>
                <label for="mail">Field</label>
                <input ngControl="Field" type="text" id="email" required #email="ngForm" pattern="[a-z0-9!#$%&'*+\/=?^_`{|}~.-]+@[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*$">
                <span class="error" *ngIf="!email.valid">Not valid</span>
            </div>
            <button type="submit" [disabled]="!ff.valid">Submit</button>
        </form>
    `
})

`之前添加一个
\
`(反勾选)


或者将模板移动到HTML文件并使用
templateUrl
而不是
template

@GünterZöchbauer刚刚更新您是否尝试将HTML移动到其自己的文件并使用
templateUrl
而不是
template
?哪种方式。看起来图案有问题。我只是将这个regex
pattern=“^\S+@\S+$”
用于测试,它也不起作用。该字段始终无效您是否尝试将HTML移出
*.ts
文件?是否在浏览器中看到
模式
属性?它与源文件中的相同吗?在模式中使用未替换的反勾号很明显。您可以使用反勾号创建多行字符串,但在字符串unscaped中使用相同的引号无法工作。我不知道为什么当你添加``时它不起作用。它似乎正确地将模式传递给HTML。你能让它在这个垃圾桶里繁殖吗?
[tslint] expected an assignment or function call
[tslint] missing whitespace
[ts] Cannot invoke an expression whose type lacks a call signature.
[ts] Cannot find name 'a'.
[tslint] expected an assignment or function call
[tslint] missing whitespace
[ts] Cannot invoke an expression whose type lacks a call signature.
[ts] The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
[ts] Cannot find name 'a'.
[tslint] missing whitespace
[ts] Expression expected.
pattern="[a-z0-9!#$%&'*+\/=?^_\`{|}~.-]+@[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*$"