加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

在特定路线中添加类 – 角度2

发布时间:2020-12-17 17:42:41 所属栏目:安全 来源:网络整理
导读:我想在某条路线上添加课程.代码在我的AppComponent中,我使用的是ngClass. @Component({ selector: 'my-app',template: `a [ngClass]="getRoute(router)" // Some html code.... }) 然后我在相同的app.component.ts上有这个功能 export class AppComponent {
我想在某条路线上添加课程.代码在我的AppComponent中,我使用的是ngClass.

@Component({
     selector: 'my-app',template: `<a [ngClass]="getRoute(router)">
       // Some html code....
    })

然后我在相同的app.component.ts上有这个功能

export class AppComponent  { 
    getRoute(){
     if (this.router.url === '/atendimento'){
      return "hide-bar";
   }
  }
 }

我得到的错误如下:

Property ‘router’ does not exist on type ‘AppComponent’

是的,我在标题上导入Routes,RouterModule和Router.有人能帮我吗?

提前致谢

解决方法

你需要注入路由器

export class AppComponent  { 

    constructor(private router:Router) {}

    getRoute(){
     if (this.router.url === '/atendimento'){

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读