【发布时间】:2017-03-19 04:50:44
【问题描述】:
您可以在此处找到示例应用:http://ivan-khludov.com/
这是我的根组件:
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 页的组件:
import { Component } from '@angular/core';
@Component({
selector: 'secapagea',
template: `
<h2>Section 1 - Page 1</h2>
<countera></countera>
`
})
export class Section1Page1 {
}
第 1 节第 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);
}
}
把我打开的第一页的案例放在该部分。有没有办法在不重新加载计数器的情况下导航到同一部分的第二页?我想为此类导航问题找到一个通用解决方案——它可能不是计数器组件,而是侧边栏导航或部分标题或其他东西。
【问题讨论】:
-
如果重要的话,这是路由:jsfiddle.net/mgdvLyua
标签: javascript angularjs angular architecture angular-routing