Posts

Showing posts with the label Angular2 Routing

Angular 2 Get Current Route

Answer : Try this, import { Router } from '@angular/router'; export class MyComponent implements OnInit { constructor(private router:Router) { ... } ngOnInit() { let currentUrl = this.router.url; /// this will give you current url // your logic to know if its my home page. } } Try it import { Component } from '@angular/core'; import { Router, NavigationEnd } from '@angular/router'; @Component({...}) export class MyComponent { constructor(private router:Router) { router.events.subscribe(event => { if (event instanceof NavigationEnd ) { console.log("current url",event.url); // event.url has current url // your code will goes here } }); } } Try any of these from the native window object. console.log('URL:' + window.location.href); console.log('Path:' + window.location.pathname); console.log('Host:' + window.location.host); console.log('Ho...

Angular 2 / Leaflet Map, How To Link To A Component From Marker Popup ? ... RouterLink?

Answer : There is a very simple approach and a very complex one. The simple approach is to use raw HTML with anchor element outside of angular without RouterLink . Register to clicks on that anchor element and use the Router service to navigate. The task was to fire links but the actual problem is far deeper, now it links next time its showing an angular component... So, for the complex solution: This is an highly advanced topic... Not only it involves using advanced angular techniques it's also advanced in the leaflet implementation. I'll do my best to convey the message but due to the complexity the examples will be very simple and will require work. First - Angular realm. An HTML string that contains directives, components or pipes will never work, the only way is to initialize a View Let's define A View as a reference to view instance of a component or a template . These are called ComponentRef and TemplateRef So, we have 2 ways to solve this ...