Javascript AngularJS指令中的动画,事件未触发

Javascript AngularJS指令中的动画,事件未触发,javascript,angularjs,Javascript,Angularjs,我正在尝试在指令中的“enter”事件之后执行某些操作。加载模板时,事件未触发 这是应用程序声明 angular .module('MyApp', [ 'ngAnimate', 'ngCookies', 'ngResource', 'ngRoute', 'ngSanitize', 'ngTouch' ]) .config(function ($routeProvider) { $routeProvider .when

我正在尝试在指令中的“enter”事件之后执行某些操作。加载模板时,事件未触发

这是应用程序声明

angular
  .module('MyApp', [
    'ngAnimate',
    'ngCookies',
    'ngResource',
    'ngRoute',
    'ngSanitize',
    'ngTouch'
  ])
  .config(function ($routeProvider) {
    $routeProvider
      .when('/', {
        templateUrl: 'views/home.html',
        controller: 'HomeCtrl'
      })
      .when('/in-the-community', {
        templateUrl: 'views/in-the-community.html',
        controller: 'CommunityCtrl'
      })
       .otherwise({
        redirectTo: '/'
      });
  });
最初,我使用路由提供程序为我提供一个模板页面。然后我尝试在这些模板中使用一个指令来提供另一个视图。这通过在我的模板页面中使用以下内容来实现

<div class="flex">
    <div class="fc fci image-wrapper" id="home-banner">
    </div>

    <div class="fc fcc">
        <section show-and-hide-content="{{ sub_content }}">
        </section>
    </div>
</div>
控制台日志没有运行,我只能推测这是因为它没有触发
$animate.on
事件

angular是否将
ng enter
类应用于指令中的
模板URL


我是angular的新手,所以如果这是一种错误的方法,那么另一种方法也会很有帮助。

由于$animate依赖项没有被拉入指令中

angular.module('MyApp')
  .directive('showAndHideContent',['$animate', function ($animate) {
    return {
      templateUrl: 'views/community-sub.html',
      controller: 'CommunitySubCtrl',
      link: function(scope, element, attributes) {
        $animate.on('enter', element,
           function callback(element, phase) {
             console.log('attributes.showAndHideContent');
           }

        );

      }

     };
   }]);

我看到你正在使用一个控制器。你不能在那里创建活动吗? 我检查了我的代码,并将此代码段放在控制器上,要在路由更改时销毁一个间隔,请注意,我使用$on和带有$的“$destroy”。会是这样吗

$scope.$on('$destroy', function () {
                    $interval.cancel($scope.interval);
                });

以前从未听说过
enter
事件,也无法通过谷歌找到有关它的smth-你是说当按下“回车键”时?@messervill,
enter
是angularjs结构事件,@ChrisTownsend什么是
容器
?您是否定义了您没有显示的地方?或者您是否打算使用
元素
?否,因此使用动画提供程序时,在使用ng view时,它会在不同的状态下添加类。我试着用一个指令来做这件事,并作为一个整体来做一些事情callback@PatrickEvans我没有在任何地方定义它,但没有任何错误。我现在已经将其更改为元素,但如果您没有得到
未捕获引用错误:容器未定义
或类似错误,则仍然没有运行事件,因为您的
链接
回调甚至没有被调用
$scope.$on('$destroy', function () {
                    $interval.cancel($scope.interval);
                });