parametro angulara con ruta y recarga de componente

Solutions on MaxInterview for parametro angulara con ruta y recarga de componente by the best coders in the world

showing results for - "parametro angulara con ruta y recarga de componente"
Jona
16 Mar 2016
1import { Component, OnInit, ElementRef, Renderer } from '@angular/core';
2import { Router, ActivatedRoute, Params } from '@angular/router';
3import { productModel } from '../_models/index';
4import { categoryListService } from '../_services/index';
5
6@Component({
7  selector: 'app-product',
8  templateUrl: 'product.component.html',
9  styleUrls: ['product.component.css']
10})
11export class productComponent implements OnInit {
12  uidproduct: productModel;
13  param: number;
14  constructor(
15    private elementRef: ElementRef,
16    private route: ActivatedRoute,
17    private router: Router,
18    private categoryListService: categoryListService) { }
19
20  ngOnInit() {
21    this.route.params.subscribe(product => {
22      console.log('logging sub product obj', product);
23    });
24    this.uidproduct = JSON.parse(sessionStorage.getItem('product'));
25    var s = document.createElement("script");
26    s.type = "text/javascript";
27    s.src = "http://this/external/script/needs/to/be/loaded/each/time.js";
28    this.elementRef.nativeElement.appendChild(s);
29  }
30  nextproduct(){ 
31    let i = this.uidproduct.order;
32    this.categoryListService.findNextproduct(this.uidproduct);
33    this.param = ++i;
34    this.router.navigate([`/product/${this.param}`]);
35  }
36}
37