I am trying to display form Control "name" in HTML
The Form control "name" is grouped inside form group : "sample"
Am not aware of hierarchy
Here is the HTML code :
<p contenteditable="true" [formControl]="name"> </p>
<div>
FORM GROUP Value : {{ sample.value | json }}
<br>
FORM CONTROL VALUE : {{sample.value.name}}
</div>
HERE IS the TYPESCRIPT CODE :
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, FormControl, Validators } from '@angular/forms';
import { Title } from '@angular/platform-browser';
import { Router } from '@angular/router';
@Component({
selector: 'app-ng-contenteditable-my-example1',
templateUrl: './ng-contenteditable-my-example1.component.html',
styleUrls: ['./ng-contenteditable-my-example1.component.scss']
})
export class NgContenteditableMyExample1Component implements OnInit {
constructor(private formbuilder: FormBuilder,
private titleService: Title,
private _router: Router) {
this.titleService.setTitle('formbuilder');
}
ngOnInit() {
// console.log("Sample Status : " + this.sample.status);
this.sample.controls.name.setValue(`Ashish`)
}
sample : FormGroup = new FormGroup({
name : new FormControl(null,[Validators.nullValidator])
});
}
I an getting this error :
NgContenteditableMyExample1Component.ngfactory.js? [sm]:1 ERROR Error: Cannot find control with unspecified name attribute
at _throwError (forms.js:3357)
at setUpControl (forms.js:3181)
at FormControlDirective.ngOnChanges (forms.js:7102)
at checkAndUpdateDirectiveInline (core.js:31906)
at checkAndUpdateNodeInline (core.js:44367)
at checkAndUpdateNode (core.js:44306)
at debugCheckAndUpdateNode (core.js:45328)
at debugCheckDirectivesFn (core.js:45271)
at Object.eval [as updateDirectives] (NgContenteditableMyExample1Component.html:23)
at Object.debugUpdateDirectives [as updateDirectives] (core.js:45259)