我有一个组件(参见:它是standalone个组件):
@Component({
standalone: true, // <--- See here
selector: "app-login",
imports: [FormsModule, CommonModule],
templateUrl: "./login.component.html",
styleUrl: "./login.component.css"
})
export class LoginComponent {
constructor(private authService: AuthService) {}
}
服务是(请看,它要求HttpClient为injected):
import { HttpClient } from '@angular/common/http';
@Injectable({
providedIn: 'root',
})
export default class AuthService {
constructor(private http: HttpClient) {} // <--- See here: if I remove this httpClient, it works.
}
它不起作用:
ERROR NullInjectorError: R3InjectorError(Standalone[e])[e -> e -> e -> e]:
NullInjectorError: No provider for e!
如果我从服务的构造函数中删除httpClient,它可以工作(但它什么也不做).在我看来,在服务中注入HttpClient不起作用.
有什么线索吗?
版本:17度角
PS:删除了大量详细信息:-)