我有以下導航鏈接:
<a (click)="mylink(someLink)">SomeLink</a>
屬于:
<div #someLink class="someLink active">
Container Content
</div>
但是相對的 TypeScript 代碼只能在同一組件中本地作業。但我想將自己的導航組件中的鏈接和內容的另一個組件外包。
mylink(page: any, event: any) {
page.classList.add('active'); // show the 'WebContainer SomeLink'
}
我怎么能意識到這一點?
uj5u.com熱心網友回復:
您可以為此使用 Angular 路由。見:https ://angular.io/tutorial/toh-pt5
生成您的應用程式時,只需對路由說“是”。在您的導航組件中構建如下鏈接:
<a [routerLink]="['yourcomponent']" ">SomeLink</a>
提示:不要使用href標簽!!!
在 app.modules.ts 檢查:
import { AppRoutingModule } from './app-routing.module';
在 app-routing.modules.ts 中匯入所有可點擊的組件:
import { YourComponent } from './yourcomponent/yourcomponent.component';
并將您的路線(例如鏈接)添加到同一個檔案中,如下所示:
const routes: Routes = [
{ path: '', component: YourStartComponent },
{ path: 'yourcomponent', component: YourComponent },
];
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/451833.html
