I am doing an online learning class to learn Angular. (LinkedIn Learning - Building Angular and ASP.NET Core Applications) in this class an interface to store a Book object is created in a subfolder interfaces under the scr/app directory. Then it appears immediately for use in components and services.
I, coming from a C++/C# background, am trying to understand how the interface is globally available as an object to be used in components or services. The project compiles and works, my question is how? The things that I would think you need to make the interface available don't exist in this project
- There is no export statement to the interface
- The interface is not imported into the file being used
- The interface is not declared in the app.module.ts file
book.ts
interface Book {
id: number;
title: string;
description: string;
author: string;
rate?: number;
dateStart?: Date;
dateRead?: Date;
}
Example of Component
export class ShowBookComponent implements OnInit {
book: Book;
Example of Service
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class BookService {
_baseURL: string = "api/Books";
constructor(private http: HttpClient) { }
getAllBooks() {
return this.http.get<Book[]>(this._baseURL+"/GetBooks");
}