Hi, I’m trying to test with ionic 7, but importing the service into a home page doesn’t work, it throws me an error that the module is not injected.
service
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
@Injectable({
providedIn: 'root'
})
export class TmsService {
constructor(private http: HttpClient) { }
getDatos() {
return this.http.get('https://jsonplaceholder.typicode.com/users');
}
}
home page
import { Component, OnInit } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { IonicModule } from '@ionic/angular';
import { HttpClient, HttpClientModule } from '@angular/common/http';
import { map } from 'rxjs/operators';
import { TmsService } from '../../services/tms.service';
@Component({
selector: 'app-home',
templateUrl: './home.page.html',
styleUrls: ['./home.page.scss'],
standalone: true,
imports: [IonicModule, CommonModule, FormsModule, HttpClientModule]
})
export class HomePage implements OnInit {
datos: any;
constructor(private tms: TmsService) { }
ngOnInit() {
this.tms.getDatos().subscribe(data => {
this.datos = data;
console.log(this.datos);
});
}
}
error generated
any suggestion? thanks
2 posts - 2 participants