[英]Add/remove class routing when he was active Angular 2
I want to add the done classes to the routing when I change it in another component: For example: I am in step1(component) click "go to step 2" in navbar routing component step1 receives classes done 我想在其他组件中更改路由时将完成的类添加到路由中:例如:我在step1(组件)中,在导航栏路由组件step1中单击“转到第2步”,接收完成的类
my navbar.html (component) 我的navbar.html(组件)
<li routerLinkActive="active" [routerLinkActiveOptions]="{exact:true}" class="step"><a [routerLink]="['step1']">
<h4 class="list-group-item-heading">Miejsce i data</h4>
</a></li>
<li routerLinkActive="active" class="step disabled"><a [routerLink]="['step1']">
<h4 class="list-group-item-heading">Wybierz samochód</h4>
</a></li>
my step1.html (component) 我的step1.html(组件)
<button (click)="goStep2()">go to step 2</button>
You could set up a variable step1Done = false
and when goStep2()
is called, within that function set this.step1Done = true
and then bind that value to a class in your html [class.done]='step1Done
您可以设置变量
step1Done = false
并在goStep2()
时在该函数中设置this.step1Done = true
,然后将该值绑定到html [class.done]='step1Done
you could handle all of that in the .ts component, use a template reference in your html <div #myDiv>
get the element in your .ts file with @ViewChild() myDiv;
您可以在.ts组件中处理所有这些问题,请在html
<div #myDiv>
使用模板引用,并通过@ViewChild() myDiv;
获取.ts文件中的元素@ViewChild() myDiv;
and then in your goStep2()
function add the class this.myDiv.nativeElement.classList.add('done')
然后在您的
goStep2()
函数中添加类this.myDiv.nativeElement.classList.add('done')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.