我使用angularJS v1.0.0创建了一个指令,一切正常,现在我更新了角度到v1.0.7并且我的指令不再工作了,我尝试了很多不同的方法来解决它,但我无法使它工作.
我尝试为$ routeChangeStart替换$ beginRouteChange,为$ routeChangeSuccess替换$ afterRouteChange但仍然不能正常工作
它只是一个文本,显示应用程序繁忙时的"加载..."按摩.你可以在这里看到解释:
http://mhevery.github.io/angular-phonecat/app/#/phones
指示:
working version in AngularJS 1.0.0 but not in v1.0.7
'use strict';
/* Directives */
var directive = {};
directive.butterBar = function($rootScope) {
return {
restrict: 'C',
link: function(scope, element) {
$rootScope.$on('$beginRouteChange', function() {
element.addClass('show');
element.text('Loading...');
});
$rootScope.$on('$afterRouteChange', function() {
element.removeClass('show');
element.text('');
});
}
};
};
angular.module('phonecatDirectives', []).directive(directive);
Run Code Online (Sandbox Code Playgroud)
谢谢!
捕获路线变化的正确事件是:
$routeChangeStart
$routeChangeSuccess
$routeChangeError
$routeUpdate
Run Code Online (Sandbox Code Playgroud)
请参阅$ route文档
用法:
$rootScope.$on('$routeChangeStart', function() {
element.addClass('show');
element.text('Loading...');
});
$rootScope.$on('$routeChangeSuccess', function() {
element.removeClass('show');
element.text('');
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
164 次 |
| 最近记录: |