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
Angular 模板与属性中的角度性能函数。如何衡量绩效?单程快吗?_Angular_Angular Forms - Fatal编程技术网

Angular 模板与属性中的角度性能函数。如何衡量绩效?单程快吗?

Angular 模板与属性中的角度性能函数。如何衡量绩效?单程快吗?,angular,angular-forms,Angular,Angular Forms,我需要显示一条消息时,输入是触摸和无效的。有几个输入,我需要这样做,所以我创建了一个函数:让我重复这个表单上有几个控件,所以我需要考虑重用,如果可能的 在HTML模板中,我执行以下操作: <input autocomplete="off" id="firstName" class="form-control" formControlName="firstName"> <div *ngIf="isInvalid(firstName)"> Please e

我需要显示一条消息时,输入是触摸和无效的。有几个输入,我需要这样做,所以我创建了一个函数:让我重复这个表单上有几个控件,所以我需要考虑重用,如果可能的

在HTML模板中,我执行以下操作:

<input autocomplete="off" id="firstName" class="form-control" formControlName="firstName">
          <div *ngIf="isInvalid(firstName)"> Please enter a valid value </div>
在html中我这样做

<input autocomplete="off" id="lastName" class="form-control" formControlName="lastName">          
          <div *ngIf="lastName.touchedAndInvalid"> Please enter a valid value </div>
我的问题是:
一种方式比另一种好吗?我如何用一些工具或扩展来证明一种方法具有更好的性能?有更好的办法吗?我疯了吗?

不确定性能指标,但我使用的惯例是

this.exampleForm=this.fb.group{ 姓氏: }; 获取有效信息{ constCtrl=this.exampleForm.get'exampleControl'; 返回ctrl.toucted&&ctrl.invalid; } 请输入有效值
不确定性能度量,但我使用的约定是

this.exampleForm=this.fb.group{ 姓氏: }; 获取有效信息{ constCtrl=this.exampleForm.get'exampleControl'; 返回ctrl.toucted&&ctrl.invalid; } 请输入有效值
我的问题是,对于表单上的每个控件,我都需要一个isValid getter。我的表格上有几个输入。如果我能证明这种方法更快,那么我可以将它添加到我从FormControl扩展的控件中。如果在getter函数中添加console.log'isValid called',您可能会看到它被多次调用。我感谢您提供的答案。我的问题是,我需要一个isValid getter用于表单上的每个控件。我的表格上有几个输入。如果我能证明这种方法更快,那么我可以将它添加到我从FormControl扩展的控件中。如果在getter函数中添加console.log'isValid called',您可能会看到它被多次调用。谢谢你的回答。
<input autocomplete="off" id="lastName" class="form-control" formControlName="lastName">          
          <div *ngIf="lastName.touched && lastName.invalid"> Please enter a valid value </div>
export class FormControlExtended extends FormControl {

    touchedAndInvalid = false;
    constructor(formState?: any,
        validatorOrOpts?: ValidatorFn | ValidatorFn[] | AbstractControlOptions | null,
        asyncValidator?: AsyncValidatorFn | AsyncValidatorFn[] | null) {
        super(formState, validatorOrOpts, asyncValidator);

        this.statusChanges
            .subscribe(() => {
                this.markTouchAndInvalid();
            });
    }


    markAsTouched({ onlySelf }: { onlySelf?: boolean } = {}): void {
        super.markAsTouched({ onlySelf });
        this.markTouchAndInvalid();
    }

    markTouchAndInvalid = () => {
        this.touchedAndInvalid = (this.touched && this.invalid);
    }
}
<input autocomplete="off" id="lastName" class="form-control" formControlName="lastName">          
          <div *ngIf="lastName.touchedAndInvalid"> Please enter a valid value </div>