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

150
Views
If URL is entered data is not fetched from Database

I have a basic app structure where I call data (the iPhones in the database) from the AppComponent itself.

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

The fetchIphones method is in my iPhoneService file where I have 3 functions.

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;
  }

The First two functions create the iPhoneList array and after that from my iPhoneFront-Component I retrive the data from the with the getiPhone function.

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

My Problem is that when I go to the page via the Navbar the data is fetched and visible, but if I go to the webpage manually via the URL the data is not fetched. My HTML for the navbar and the AppModule are below.

<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},
]

Thanks in Advance :)

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!