I have a question to Angular 5 Components, My Component looks like this:
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { AuthService } from './../auth/auth.service';
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.css'],
providers: [FormBuilder, AuthService] // is this line needed?
})
export class LoginComponent implements OnInit {
constructor(private fb: FormBuilder, private authService: AuthService) { }
ngOnInit() {
}
}
Without the line providers: [FormBuilder, AuthService] I geht the following exception:
NullInjectorError: No provider for FormBuilder!
If I add providers: [FormBuilder, AuthService] then all works fine. My question now would be if this line is really necessary because I saw Components in a tutorial without the line providers: [FormBuilder, AuthService] (e.g. Creating the Login component)