Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Angular, define global variable over components for navigation

I have the following navigation link:

<a (click)="mylink(someLink)">SomeLink</a>

Which belongs to:

<div #someLink class="someLink active">
 Container Content
</div>

But the relative TypeScript code works only local in the same compoment. But I want outsource the links in an own navigation component and another component for the content.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

mylink(page: any, event: any) {
    page.classList.add('active'); // show the 'WebContainer SomeLink'
}

How can I realise this?

>Solution :

You can use Angular Routing for this. See: https://angular.io/tutorial/toh-pt5

When generating your app, just say "Yes" to Routing.
In your navigation component build a link like the following:

<a [routerLink]="['yourcomponent']" ">SomeLink</a>

Hint: Do not use a href tag !!!

In app.modules.ts check for:

import { AppRoutingModule } from './app-routing.module';

In app-routing.modules.ts import all clickable components:

import { YourComponent } from './yourcomponent/yourcomponent.component';

and add your routes (e.g. links) in the same file like this:

const routes: Routes = [
  { path: '', component: YourStartComponent },
  { path: 'yourcomponent', component: YourComponent },
];
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading