Angular add class dynamically

前端 未结 3 1299
隐瞒了意图╮
隐瞒了意图╮ 2021-02-08 04:05

Is there a way to add a class from the .ts file, using Angular solutions

I want to d

3条回答
  •  时光取名叫无心
    2021-02-08 04:31

    While the solution with the Renderer works, I am proposing you create a data structure for your buttons

    buttons: Array<{label: string}> = [
        {
          label: 'Global'
        },
        {
          label: 'Maintenance'
        },
        {
          label: 'Settings'
        },
        {
          label: 'Profile'
        },
        {
          label: 'Transactions'
        }
      ]
    

    This can easily be iterated through using ngFor

    
    

    And only thing your ChangeScreen method would need is... the thing its already doing, setting the current page!

    See stackblitz for an example of how this plays out.

提交回复
热议问题