引用我自己的话
here
:
-
在
$routeChangeStart
ngClass
要删除
active
-
同时
$route
开始准备进入视图,包括获取其模板。
-
一旦一切就绪,它就会触发
$routeChangeSuccess
ngView
开始交换两个视图。
-
在交换过程中,
ngView公司
破坏了离开视图的范围,从这一点开始,范围的观察者停止。。。注视。
ngClass公司
要删除
忙碌的
班第一次访问路线时,动画会起作用,因为
必须向服务器请求输入视图的模板(该模板提供
ngClass公司
是时候做它的工作了)。但是,当您访问以前访问过的路由时,模板已经缓存,转换速度很快。
app.decorator('$templateRequest', ($delegate, $timeout) => {
const $templateRequest = (...args) => $delegate(...args).
then(tmpl => $timeout().then(() => tmpl));
Object.defineProperty($templateRequest, 'totalPendingRequests', {
get: () => $delegate.totalPendingRequests,
set: nv => $delegate.totalPendingRequests = nv,
});
return $templateRequest;
});
(
Updated plnkr 1
)
ngClass公司
,以便在销毁离开视图的范围之前立即应用类。这种指令的未优化、非生产就绪的crud版本可能如下所示:
app.directive('myClass', () => (scope, elem, attrs) => {
scope.$watchCollection(attrs.myClass, newValue => {
Object.keys(newValue).forEach(c => {
if (newValue[c]) {
elem.addClass(c);
} else {
elem.removeClass(c);
}
});
});
});
(
Updated plnkr 2
-
).
-
animationProperties.visibility.views
)这触发了
ngClass公司
-
移除该类会触发CSS动画。
-
同时,有一个自定义的JavaScript动画(
animation('.view')
)将自身与CSS动画同步,然后设置回标志。
-
通过设置回标志,为进入的视图触发相反的CSS动画。
对于初学者来说,为什么同时使用CSS和JS动画?例如,您可以处理JS动画中的不透明度更改(假设您的实际设置更复杂,并且需要JS动画来实现其他效果)。
或者,您可以更轻松地使用基于自动添加/删除的纯CSS动画处理淡入/淡出
ng-enter
ng-leave
类(只有4个小小的CSS规则:smiley:):
[ng-view].ng-enter {
/* Wait for the leaving view to...leave, then start transitioning in. */
transition: opacity 1s ease 1s;
}
[ng-view].ng-leave {
/* Start transitioning out. */
transition: opacity 1s ease;
}
[ng-view].ng-enter,
[ng-view].ng-leave.ng-leave-active {
/*
* At the beginning of the entering animation and
* at the end of the leaving animation,
* the view must be fully invisible.
*/
opacity: 0;
}
[ng-view].ng-enter.ng-enter-active,
[ng-view].ng-leave {
/*
* At the end of the entering animation and
* at the beginning of the leaving animation,
* the view must be fully visible.
*/
opacity: 1;
}
(
Updated plnkr 3