I don't quite understand the writing of those functions in angular. Please mention it.

export class RepeatPasswordDirective implements Validator,OnChanges {
/ * *

  • check method
  • @ param c
  • @ returns {{[p: string]: any}}

* /
validate (c: AbstractControl): {[p: string]: any} {

return verifyPassword(c,this.repeatPassword.control);

}

ngOnChanges (changes: SimpleChanges): void {

  this.repeatPassword=changes["repeatPassword"].currentValue;

}

/ *

  • pass in the model of another input tag through the attribute
  • The
  • name is the same as the selector, so there is no need to add additional attributes to pass in
  • when using it.

* /
@ Input () repeatPassword:NgModel;
constructor () {}

}

< hr >

validate (c: AbstractControl): {[p:string]: any} {
}
like this function, the return value is {[p:string]: any}. What does it mean to put a key-value pair in square brackets?


this is typescript syntax

add : after the function parentheses to indicate the function return type

here means that the type of the returned value is a JSON object, the key of the JSON object is a value of any string type, value can be of any type, any .


specifies that the return value is an object,
key is of type string and can be any string value.
value is any type of any.

Menu