javascript - Angular 2 : How do you import routerLink exclusively - Stack Overflow

How do you import the routerLink directive exclusively in Angular 2ProblemI'm making a mon module

How do you import the routerLink directive exclusively in Angular 2

Problem

I'm making a mon module for my app and I use routerLink everywhere but nothing else in the RouterModule so I'm wanting a way to get access to the directive without importing everything.

What I Know

I know to get the routerLink directive you need to import the RouterModule, like so.

import { RouterModule } from '@angular/router';

I also know that all modules just import, declare, and export ponents, service and so on. So in theory the routerLink should be able to be imported directly but I can't find out how.

How do you import the routerLink directive exclusively in Angular 2

Problem

I'm making a mon module for my app and I use routerLink everywhere but nothing else in the RouterModule so I'm wanting a way to get access to the directive without importing everything.

What I Know

I know to get the routerLink directive you need to import the RouterModule, like so.

import { RouterModule } from '@angular/router';

I also know that all modules just import, declare, and export ponents, service and so on. So in theory the routerLink should be able to be imported directly but I can't find out how.

Share Improve this question asked Feb 10, 2017 at 14:45 Michael WarnerMichael Warner 4,2573 gold badges24 silver badges48 bronze badges 3
  • 2 In your app.ponent I guess you have declared some routes using something like RouterModule.forRoot(ROUTES, {useHash: false}),. That basically provides all the needed router directives for your app. Just add RouterModule to your mon modules as I would guess routing is going to be a mon thing in your app. You will always need the RouterModule to be present to use its directives, no point in trying to just import the routerLink directive with no RouterModule? – rtn Commented Feb 10, 2017 at 14:58
  • you've got a very good point – Michael Warner Commented Feb 10, 2017 at 15:15
  • I don't think you can use routerLink without importing the whole RouterModule. – Ben Richards Commented Feb 10, 2017 at 15:55
Add a ment  | 

1 Answer 1

Reset to default 5

Now in 2023 you can import RouterLink):

import { RouterLink } from '@angular/router';

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742386415a4434150.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信