Created
October 2, 2016 14:23
-
-
Save lacolaco/31d3ae4cc036edb15846f6287ecee454 to your computer and use it in GitHub Desktop.
pseudo-routerlink
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component({}) | |
class SomeCmp { | |
containerElement: HTMLElement; | |
constructor(private router: Router) {} | |
ngOnInit() { | |
// insert HTML to DOM | |
containerElement.innerHTML = `<a href="/foo">Link</a>` | |
// query anchors | |
const anchors = containerElement.querySelectorAll('a[href]'); | |
Array.from(anchors).forEach(el => { | |
el.addEventListener('click', e => { | |
e.preventDefault(); | |
this.router.navigateByUrl(el.getAttribute('href')); | |
}); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment