gpt4 book ai didi

html - 如何使下拉菜单不重新加载插入符号单击 Angular 2 上的页面

转载 作者:太空狗 更新时间:2023-10-29 18:26:36 27 4
gpt4 key购买 nike

我正在开发 Angular 2 应用程序,我已经按照 Bootstrap 示例为菜单栏创建了一个 HTML 组件。每当我单击第 1 页附近的插入符号时,它都会重新加载整个页面,而不仅仅是显示子菜单。我做错了什么?

菜单栏:

<nav class="navbar navbar-inverse" *ngIf="showNavBar">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">Streams</a>
</div>
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
Page 1
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li><a href="#">Page 1-1</a></li>
<li><a href="#">Page 1-2</a></li>
<li><a href="#">Page 1-3</a></li>
</ul>
</li>
<li><a href="#">Page 2</a></li>
<li><a href="#">Page 3</a></li>
</ul>
</div>
</nav>

应用程序组件.ts

import { Component } from 'angular2/core';
import { LoginComponent } from './home/login.component';
import { WelcomeComponent } from './home/welcome.component';
import { HTTP_PROVIDERS } from 'angular2/http';
import { RouteConfig, ROUTER_DIRECTIVES } from 'angular2/router';
import { TopNavbarComponent } from './navbar.component';

@Component({
selector: 'cmt-app',
template: `<div class='container'>
<navbar></navbar>
<router-outlet></router-outlet>
</div>
`,
directives: [ROUTER_DIRECTIVES, TopNavbarComponent],
providers: [HTTP_PROVIDERS]
})

@RouteConfig([
{ path: '/login', name: 'Login', component: LoginComponent, useAsDefault: true },
{ path: '/welcome', name: 'Welcome', component: WelcomeComponent }
])

export class AppComponent {

}

最佳答案

href="#" 有问题。尝试使用 href="javascript:void(0)"

<a class="dropdown-toggle" data-toggle="dropdown" href="javascript:void(0)">
Page 1
<span class="caret"></span>
</a>

关于html - 如何使下拉菜单不重新加载插入符号单击 Angular 2 上的页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38742442/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com