unique validator angular reactive form

Solutions on MaxInterview for unique validator angular reactive form by the best coders in the world

showing results for - "unique validator angular reactive form"
Emily
02 Jul 2016
1// How to check for unique validity in MEAN stack apps
2// Backend : Node + Express + MongoDB
3// DB-backend communication : mongoose + mongoose_unique_validator
4// Angular script to show validations errors in UI
5// You have to match angular's formControlNames with mongoose's model fields
6
7// Init
8fg: FormGroup
9constructor(private $http: HttpClient) {}
10
11// your http request
12this.$http.post('//my_post_url', data).subscribe(
13  (e) => {
14  	console.log('All is well')
15  },
16  (error) => {
17    console.error('we got errors')
18    Object.keys(error.errors)
19      .map((errorKey) => errors[errorKey].path)
20      .forEach((path) => {
21      	// path: name of mongoose schema field where unique error occured
22        this.fg.get(path).setErrors({ notUnique: true })
23      })
24  }
25)