Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
AngularJS v1.0.0指令在v1.0.7中不起作用_Angularjs - Fatal编程技术网

AngularJS v1.0.0指令在v1.0.7中不起作用

AngularJS v1.0.0指令在v1.0.7中不起作用,angularjs,Angularjs,我使用angularJS v1.0.0创建了一个指令,一切正常,现在我将angular更新为v1.0.7,我的指令不再工作,我尝试了许多不同的方法来修复它,但我无法使它工作 我尝试将$beginRouteChange替换为$routeChangeStart,将$afterRouteChange替换为$RouteChangeSuccessful,但仍然无法工作 它只是一个文本,在应用程序繁忙时显示“加载…”消息。您可以在此处看到解释示例: 指令: working version in Angul

我使用angularJS v1.0.0创建了一个指令,一切正常,现在我将angular更新为v1.0.7,我的指令不再工作,我尝试了许多不同的方法来修复它,但我无法使它工作

我尝试将$beginRouteChange替换为$routeChangeStart,将$afterRouteChange替换为$RouteChangeSuccessful,但仍然无法工作

它只是一个文本,在应用程序繁忙时显示“加载…”消息。您可以在此处看到解释示例:

指令:

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);
谢谢

请检查文档:

$beginRouteChange
$afterRouteChange
不受支持


改为使用
$routeChangeStart
$routeChangeSuccess

捕捉路线更改的正确事件为:

$routeChangeStart
$routeChangeSuccess
$routeChangeError
$routeUpdate

在您的情况下的用法:

$rootScope.$on('$routeChangeStart', function() {
    element.addClass('show');
    element.text('Loading...');
});
$rootScope.$on('$routeChangeSuccess', function() {
    element.removeClass('show');
    element.text('');
});

你说的换路线是什么意思?这与我的问题有什么关系?你听到的是错误的事件,我更新了我的答案以适应你的情况。谢谢@Umur我更改了代码,但仍然不起作用:directive.butterBar=function($rootScope){return{restrict:'C',link:function(scope,element){$rootScope.$on('$routeChangeStart',function(){element.addClass('show');element.text('Loading…');});$rootScope.$on('$routeChangeSuccess',function(){element.removeClass('show');element.text('';});};};};