Attaching click to anchor tag in angular

前端 未结 13 1675
臣服心动
臣服心动 2020-12-13 12:02

I am trying to attach click event to anchor tags (coming from ajax) and block the default redirection. How can I do it in angular ?



        
13条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-13 13:02

    You can use routerLink which is an alternative of href for angular 2.** Use routerLink as below in html

    My Link
    

    and make sure you register your routerLink in modules.ts or router.ts like this

    const routes: Routes = [
      { path: 'dashboard', component: DashboardComponent }
    ]
    

提交回复
热议问题