. . , .
this.title = camelize(lastPartOfUrl.replace(/-/g,' '));
function camelize(str) {
return str.replace(/(?:^\w|[A-Z]|\b\w|\s+)/g, function(match, index) {
if (+match === 0) return "";
return index == 0 ? match.toLowerCase() : match.toUpperCase();
});
}
- /.
javascript ( )
this._router.events.subscribe((event) => {
console.log('route changed');
var url = window.location.toString();
var ar = url.split('/');
var lastPartOfUrl = ar[ar.length-1];
this.title = "Title "+lastPartOfUrl ;
});
angular path ( ). , .path()
this._router.events.subscribe((event) => {
console.log('route changed');
var lastPartOfUrl = this.location.path();
this.title = "Title "+lastPartOfUrl ;
});
Edit
Title 1. , . if, /
, URL-
http://stackoverflow.com/questions/38613960/angular2-using-router-subscribe-to-watch-url-change. URL-,
this._router.events.subscribe((event) => {
console.log('route changed');
var lastPartOfUrl = this.location.path();
this.title = camelize(lastPartOfUrl.replace(/-/g,' '));
});