Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

136
Views
Si se ingresa la URL, los datos no se obtienen de la base de datos

Tengo una estructura de aplicación básica donde llamo a los datos (los iPhones en la base de datos) desde el propio AppComponent.

 ngOnInit(): void { this.iphoneservice.fetchIphones(); }

El método fetchIphones está en mi archivo iPhoneService donde tengo 3 funciones.

 iPhoneList:iPhone[]=[] fetchIphones(){ this.http .get('https://angular-project-62585-default-rtdb.firebaseio.com/iphone.json') .pipe( map(responseData =>{ const postArray =[]; for(const key in responseData){ if(responseData.hasOwnProperty(key)){ postArray.push({...responseData[key],id:key}); } } return postArray }) ) .subscribe(post =>{ this.generateIphoneList(post) }) } // Generating the IphoneList from the fetched Data generateIphoneList(post){ this.iPhoneList=[]; for (let iphones of post){ let iphone = new iPhone() for (let property in iphones){ iphone[property]=iphones[property]; } this.iPhoneList.push(iphones); } } // Returning the IphoneList to desired components getiPhone(){ return this.iPhoneList; }

Las dos primeras funciones crean la matriz iPhoneList y luego desde mi iPhoneFront-Component recupero los datos con la función getiPhone.

 ngOnInit(): void { this.iPhoneList=this.iphoneservice.getiPhone(); }

Mi problema es que cuando voy a la página a través de la barra de navegación, los datos se obtienen y son visibles, pero si voy a la página web manualmente a través de la URL, los datos no se obtienen. Mi HTML para la barra de navegación y AppModule están a continuación.

 <li class="nav-item"> <a class="nav-link" routerLink="/iphone" routerLinkActive="active" [routerLinkActiveOptions]="{exact:true}">iPhone</a> </li> const appRoutes : Routes =[ {path:'iphone', children:[ {path:'',component:IphonefrontComponent}, {path:':id',component:IphonedetailComponent}, ] }, {path:'iphone-managing', canActivate:[AuthenticationGuard], children:[ {path:'',component:IphonebackComponent}, {path:'create',component:IphonecreateComponent}, {path:':id',component:IphoneeditComponent}, ]}, {path:'cart',component:CartComponent}, {path:'authentication',component:AuthenticationComponent}, ]

Gracias de antemano :)

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!