From the course: Building Angular and Django Apps

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Creating a basic form as an Angular component

Creating a basic form as an Angular component

From the course: Building Angular and Django Apps

Start my 1-month free trial

Creating a basic form as an Angular component

- [Instructor] Let's create a form component so that users can create new tour packages. We import the form control and the form group from Angular forms, which provides a way to construct reactive forms that use two-way data bind. In our create tour form component, we add two instance variables, package form, which is a form group, and one input to the component, which is id, the id of an existing package. In the constructor, we're going to be depending on the tour package controller. And in the lifecycle on Angular component, this constructor is called once, to inject this dependency. In contrast, the ngOnInit method is called every time the component is initialized and injected into the DOM. So we're going to set up the default values for the package form, by creating a new form group, we set up the id, and the default is zero to indicate it's a new package. And then, we're going to set up the other fields, the…

Contents