Currently, I am trying to find a way to pass a Mac ID into a service using routes in order to filter data efficiently. In my app.html file, there is a dropdown menu where I manually input a list of Mac addresses. Through Angular activated routes, I am attempting to figure out how to retrieve the Mac ID and utilize it in an Angular service for filtering purposes.
[app.html]
<ul class="dropdown-menu scrollable-menu" role="menu">
<li><a routerLink="mac/:id">3s-ds-23-sf-23-ce-33</a></li>
<li><a routerLink="mac/:id">3s-ds-23-sf-23-ce-34</a></li>
<li><a routerLink="mac/:id">3s-ds-23-sf-23-ce-35</a></li>
</ul>
service.ts
@Injectable()
export class TabuleService {
//private headers = new Headers({'Content-Type': 'application/json'});
private _Url = 'http://localhost:3000'; // URL to web api
constructor(
private _http: Http,
private route: ActivatedRoute ) {}
getTemperature(): Observable<testing\[\]> {
const url = this._Url+'/temperature';
return this._http.get(url)
.map(res =>{
let data=res.json();
let parsedData = \[\];
// To effectively filter the data, I need to extract the parameter of mac from the routes
data.filter(function(el){ return el.mac=="3s-ds-23-sf-23-ce-35" })
.forEach(function(item){ parsedData.push({
x:item.epoch_time_stamp, y:parseFloat(item.temp) }); });
//console.log(parsedData);
return parsedData; })
.catch(this.handleError);
}