のための共通する成分をリロードせずにWebページをナビゲートあなたは例のアプリを見つけることができます:http://ivan-khludov.com/2角度 - ここでは、それらのページ
は、これは私のルートコンポーネントです:
import { Component } from '@angular/core';
@Component({
selector: 'root',
template: `
<h1>My Dummy Angular App</h1>
<router-outlet></router-outlet>
<nav>
<a routerLink="/section-1/1" routerLinkActive="active">Section 1 - Page 1</a>
<span>||</span>
<a routerLink="/section-1/2" routerLinkActive="active">Section 1 - Page 2</a>
<span>||</span>
<a routerLink="/section-2/1" routerLinkActive="active">Section 2 - Page 1</a>
<span>||</span>
<a routerLink="/section-2/2" routerLinkActive="active">Section 2 - Page 2</a>
</nav>
`
})
export class AppWrapper {
}
セクションのためのコンポーネント1、ページ1:セクション1用
import { Component } from '@angular/core';
@Component({
selector: 'secapagea',
template: `
<h2>Section 1 - Page 1</h2>
<countera></countera>
`
})
export class Section1Page1 {
}
ほぼ同じもので、2ページ:
import { Component } from '@angular/core';
@Component({
selector: 'secapageb',
template: `
<h2>Section 1 - Page 2</h2>
<countera></countera>
`
})
export class Section1Page2 {
}
カウンタ成分:
import { Component } from '@angular/core';
@Component({
selector: 'countera',
template: `
<div>Seconds elapsed: {{this.count}}</div>
`
})
export class Section1Counter {
count: number;
constructor() {
this.count = 0;
setInterval(() => {
this.count ++;
}, 1000);
}
}
私はセクションの最初のページを開いた場合を置きます。カウンターを再ロードせずに同じセクションの2ページ目に移動する方法はありますか?私はそのようなナビゲーションの問題のための一般的な解決策を見つけたいと思っています。それは、カウンターコンポーネントではなく、サイドバーのナビゲーションやセクションの見出しなどです。
重要な場合は、これがルーティングです。https://jsfiddle.net/mgdvLyua/ – Lzhelenin