我在TypeScript中编写了一个Angular2服务,它将使用localstorage.我想将浏览器窗口对象的引用注入我的服务,因为我不想引用任何全局变量.像角1.x的localstorage.我怎么做?
我正在使用角度5.我有一个仪表板,我有几个部分内容很少,几个部分内容如此之大,以至于我在更换路由器时遇到问题.每次我需要滚动到顶部.任何人都可以帮助我解决这个问题,以便当我更改路由器时,我的视图始终保持在顶部.
提前致谢.
如何导航到使用id属性标识的页面的某些部分?
例:
我需要导航到我页面上的"结构"段落
<div id="info">
<h3>Info</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
<div id="structure">
<h3>Structure</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
Run Code Online (Sandbox Code Playgroud)
我有一个以下导航结构:
<li>
<ul materialize="collapsible" class="collapsible" data-collapsible="accordion">
<li><a routerLink="policies" class="collapsible-header">Policies</a>
<div class="collapsible-body">
<ul>
<li><a >Info</a></li>
<li><a >Structure</a></li>
<li><a >Something Else</a></li>
</ul>
</div>
</li>
</ul>
</li>
Run Code Online (Sandbox Code Playgroud)
据我所知,在Angular1.0中,我只需使用以下内容导航到页面部分:ui-sref ="policies({'#':'structure'})"或href ="#structure"或ui -sref ="policies"href ="#structure"......
我怎么能在Angular2中做到这一点?我查看了文档中的Fragment示例:查询参数和片段部分,我发现它们的例子非常令人困惑,对于这样一个潜在的简单任务来说有点矫枉过正
我真的在这里挣扎.我们正在使用md-sidenav-layout并且发现无法想出一种方法将md-toolbar修复到页面顶部:
|--------------------------------|
| <------ md-toolbar -------> | <- fix this so content scrolls under
|--------------------------------|
| ^|
| scrollable |
| v|
----------------------------------
Run Code Online (Sandbox Code Playgroud)
因为md-sidenav-layout似乎可以解决自己的问题,所以添加
style: fixed
Run Code Online (Sandbox Code Playgroud)
到md工具栏不修复它 - 事实上似乎没有!
任何帮助赞赏.
我正在开发一个项目,其中有很多路线,每次单击链接转到特定路线时,页面不会自动滚动到顶部,这很烦人而且不好。请问有人知道如何解决这个问题吗?
我一直在尝试保持包含数百行数据的网格的元素的滚动位置。现在它设置为overflow-y: auto。如果我使用路由器转到不同的页面然后返回,我希望滚动条位于相同的位置。我认为使用 ngAfterViewInit 可以解决问题,但不幸的是它不起作用。如果我使用控制台启动设置位置命令,它可以正常工作。我猜问题是在调用 ngAfterViewInit 时行仍在加载但尚未渲染。
@Component({
selector: 'grid',
templateUrl: './grid.component.html',
styleUrls: ['./grid.component.scss']
})
export class GridComponent implements OnInit, OnDestroy {
@Input() rows: Array<Row>;
@Input() someKindOfGridId: string;
localGridConfigValue: ILocalGridConfigValue;
constructor(private configService: ConfigService) { }
ngOnInit() {
this.localGridConfigValue = this.configService.getConfigForCurrentGrid(this.someKindOfGridId);
}
ngAfterViewInit(){
document.getElementById(this.someKindOfGridId).scrollTop = this.localGridConfigValue.gridScrollTopPos;
}
ngOnDestroy() {
this.localGridConfigValue.gridScrollTopPos = document.getElementById(this.someKindOfGridId).scrollTop;
}
}
Run Code Online (Sandbox Code Playgroud)
我仍在学习角度,任何帮助将不胜感激。
问候。
我正在构建一个基本的 Angular 应用程序,我有一些组件,当我进入服务页面时,从我的主页向下滚动,然后返回主页,滚动设置到页面底部。
每次打开组件时,我都想将滚动设置为顶部。
由于我使用的是 angular7,因此我尝试使用路由器中可用的选项,
{scrollPositionRestoration : 'enabled'}
然后
{scrollPositionRestoration : 'top'},
但它不适用于 Chrome、Chrome 移动设备或 Edge。
除此之外,我尝试在路由器上设置一个侦听器并使用
window.scrollTop(0,0),这也不起作用,使用文档变量也没有。
我只想要我的滚动条在顶部。它是如此天真的事情,但它现在让我感到沮丧。
在某些情况下,我想在 Angular 中加载页面时向下滚动到某个部分。
请注意:我想向下滚动而不单击任何内容(即ngOnInit)。
我尝试了这个:在我的component.html文件中
<div #sectionSubscribe>
HTML...
</div>
Run Code Online (Sandbox Code Playgroud)
在我的 component.ts 文件中
ngOnInit(){
this.scrollToSubscribe(sectionSubscribe);
}
scrollToSubscribe($element){
$element.scrollIntoView({
behavior: 'smooth',
block: 'start',
inline: 'nearest'
});
}
Run Code Online (Sandbox Code Playgroud)
但它不允许我这样做。请帮忙
我已经尝试autoscroll="false"了router-outlet但似乎没有工作,是否有任何默认方法angular2做同样不使用任何第三方库?
angular ×8
javascript ×2
routing ×2
typescript ×2
angular9 ×1
fragment ×1
navigation ×1
scroll ×1
scrolltop ×1