Conditionally add RouterLink or other attribute directives to an element in Angular 2

后端 未结 5 977
孤独总比滥情好
孤独总比滥情好 2020-12-29 18:15

In Angular 2 if I have an element like how can I conditionally add an attribute directive like [routerLink]=\"[\'SomeRoute\'

5条回答
  •  感情败类
    2020-12-29 18:23

    Just a detail. Try to avoid using buttons for navigation. Screenreaders wont understand that its a navigation out of the box. You will now need to add an aria-label that tells the screenreaders what it does. This adds more code. But the simple solution would be to add the [routerLink] to an anchor link. Then style it as a button. But I prefer to use the standard blue links because people usually knows what will happen then. ex: I would never try to rightclick on a button and open it in a new tab. So: buttons for operations and anchorlinks for navigation

提交回复
热议问题