我目前正在Angular2中构建一个应用程序,其中有一个主屏幕:

<div id="freewall" class="free-wall" data-min-width="1840" data-total-col="5" data-total-row="4" data-wall-width="1873" data-wall-height="800" style="position: relative; height: 800px;">
<div *ngFor="let block of blokken | async" [@animState]="block.state" (click)="block.toggleState()" [ngClass]='block.color' class='blockexnr{{block.id}} live-tile cell tile2' data-mode='slide' style.height="{{block.height}}px" style.width="{{block.width}}px"
style='display: none;'>
<div>
<p class='full' href='#' class="blocknr{{block.id}}">{{block.tekst1}}</p>
</div>
<div data-mode='carousel' data-start-now='true' class='title2 live-tile' data-direction='horizontal' data-delay='3000'>
<div class="blocknr{{block.id}}">
<p>{{block.textCar[0]}}</p>
<img class='products' src='{{block.imgCar[0]}}' />
</div>
<div *ngIf="block.amountCar > 1" class="blocknr{{block.id}}">
<p>{{block.textCar[1]}}</p>
<img class='products' src='{{block.imgCar[0]}}' />
</div>
<div *ngIf="block.amountCar > 2" class="blocknr{{block.id}}">
<p>{{block.textCar[2]}}</p>
<img class='products' src='{{block.imgCar[0]}}' />
</div>
<div *ngIf="block.amountCar > 3" class="blocknr{{block.id}}">
<p>{{block.textCar[3]}}</p>
<img class='products' src='{{block.imgCar[0]}}' />
</div>
<div *ngIf="block.amountCar > 4" class="blocknr{{block.id}}">
<p>{{block.textCar[4]}}</p>
<img class='products' src='{{block.imgCar[0]}}' />
</div>
<div *ngIf="block.amountCar > 5" class="blocknr{{block.id}}">
<p>{{block.textCar[5]}}</p>
<img class='products' src='{{block.imgCar[0]}}' />
</div>
</div>
</div>
如您所知,它循环遍历一个名为blokken的20个项目的列表。还有一个名为@动画的动画,它可以通过单击时调用的函数来激活(单击)。这就是这个功能:
toggleState() {
var numberofblock = this.id;
var n = ".blocknr" + numberofblock.toString();
var n2 = ".blockexnr" + numberofblock.toString();
console.log(n);
console.log(n2);
$(n).html("");
$(".cell").not(n2).css("z-index", -1);
this.state = (this.state === 'active' ? 'inactive' : 'active'); }该函数将块的状态更改为active,在这种情况下,该块缩放:
trigger('animState', [
state('inactive', style({
transform: 'scale(1)'
})),
state('active', style({
transform: 'scale(10)'
})),
transition('inactive => active', animate('2000ms ease-in')),
])这一切都很好,但我实际上想要发生的是,当单击一个块时,它会缩放,然后路由到一个新页面。但是当我添加一个routerLink时,它根本不属于toggleState()函数,它所做的就是路由到新组件。
我也尝试了@route动画,但是里面的动画适用于整个组件--而不仅仅是一个div --这不是我想要的。
我一直在谷歌上搜索不太成功,我唯一发现的是我可能会使用解析器,但我也不太确定。
有人能帮我把这件事做好吗(所以当点击一个块时,事情的顺序是这样的:
我希望有人能帮我这个忙。谢谢!
发布于 2017-01-01 18:52:59
如果有人结巴进入这个帖子,这实际上是非常容易的。
唯一需要的是
constructor(private router: Router){}
this.router.navigate(["/LINK"]);所以我只需要用this.router调用一个函数,仅此而已。这样就不需要routerLink了。
https://stackoverflow.com/questions/41407708
复制相似问题