example project:
import { Injectable } from '@angular/core';
interface Todo {
id: string,
title: string,
description: string
}
@Injectable()
export class TodoService {
public todos: Todo[] = [];
constructor() {
// Set some test todos
this.todos = [
{ id: 'todo-one', title: 'Todo One', description: 'Do Stuff' },
{ id: 'todo-two', title: 'Todo Two', description: 'Do Stuff' },
{ id: 'todo-three', title: 'Todo Three', description: 'Do Stuff' },
{ id: 'todo-four', title: 'Todo Four', description: 'Do Stuff' },
{ id: 'todo-five', title: 'Todo Five', description: 'Do Stuff' },
{ id: 'todo-six', title: 'Todo Six', description: 'Do Stuff' },
{ id: 'todo-seven', title: 'Todo Seven', description: 'Do Stuff' }
];
}
getTodo(id): Todo {
return this.todos.find(todo => todo.id === id);
}
}
I’m project:
I can’t get data
btc.service.ts
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable, throwError } from 'rxjs';
import { ActivatedRoute } from '@angular/router';
import { NavController, ModalController } from '@ionic/angular';
import { Router } from '@angular/router';
interface Item {
//I've tried...
/*
id: string,
name: string,
symbol: string,
rank: number,
price_usd: number,
price_btc: number,
24h_volume_usd: number,
market_cap_usd: number,
available_supply: number,
total_supply: number,
max_supply: number,
percent_change_1h: number,
percent_change_24h: number,
percent_change_7d: number,
last_updated: number
*/
}
@Injectable({
providedIn: 'root'
})
export class BtcService {
public items: Item[] = []; //items:any;
constructor (public http: HttpClient) {
let data:Observable<any>;
data = this.http.get('https://api.coinmarketcap.com/v1/ticker/');
data.subscribe(result => {
this.items = result;
});
/*this.items = this.http.get('https://api.coinmarketcap.com/v1/ticker/');
this.items.subscribe(data => {
console.log('my data:', data);
}) */
}
getItem(id): Item {
return this.items.find(item => item.id === id);
}
}
currency.page.ts
import { Component, OnInit } from '@angular/core';
import { NavParams, NavController, ModalController } from '@ionic/angular';
import { ActivatedRoute } from '@angular/router';
import { HttpClient } from '@angular/common/http';
import { Observable, throwError } from 'rxjs';
import { BtcService } from '../btc.service';
import { Router } from '@angular/router';
@Component({
selector: 'app-currency',
templateUrl: './currency.page.html',
styleUrls: ['./currency.page.scss'],
})
export class CurrencyPage implements OnInit {
private item;
constructor(private route: ActivatedRoute, private BtcService: BtcService){
}
ngOnInit() {
}
ionViewWillEnter(){
let itemId = this.route.snapshot.paramMap.get('id');
this.item = this.BtcService.getItem(itemId);
}
}
home.page.html
<ion-header>
<ion-toolbar>
<ion-title>
Ionic Blank
</ion-title>
</ion-toolbar>
</ion-header>
<ion-content padding>
<button full (click)="goItemPage()">Go Item Page</button>
<ion-list>
<ion-item [href]="'/currency/' + item.id" detail="true" *ngFor="let item of BtcService.items">
{{item.id}}
</ion-item>
</ion-list>
The world is your oyster.
<p>If you get lost, the <a target="_blank" rel="noopener" href="https://ionicframework.com/docs/">docs</a> will be your guide.</p>
</ion-content>
@blondie63 , @OliverPrimo @MattE @brandyshea @mhartington
help me please easy english ım turkısh
I can’t get data detail image