2014-02-09 2 views
2

может ли кто-нибудь дать мне пример того, как смотреть события испускания на ng-include? быть точным, я хочу посмотреть на событие $ includeContentLoaded в моей директиве ... вот мой HTML:просмотр событий ng-include?

<div class="page_container"> 
    <div ng-include="menu" class=""></div> 
<section> 
     <about ng-click="loadpantone()"> 

     </about> 
     <div class="pantone_wrapper"> 
      <div ng-include="template" tabindex="0" id="focus_force" ng-keydown="keypress($event.keyCode)" ng-class="PrevNext" class="pantoneani remo pantonebg blue" ></div> 
     </div> 
</section> 
<section class="right_side"><p>Build a Web doctor</p></section> 
</div> 

директива:

'use strict'; 
/*global $:false */ 
angular.module('bawdApp') 
    .directive('about', function() { 
    return { 
     templateUrl: 'views/pantone-inner.html', 
     restrict: 'AE', 
     link: function postLink($scope, element, $emit) { 
       function border(valueWidth){ 
        $('.page_cont_wrap').css('border', valueWidth+'px solid #aaFFFF'); 
       } 
     $(element).css({'position': 'absolute'}).delay(200).animate({ 
        'margin-left': '-160px', 
        'margin-top': '-233px', 
        'left': '50%', 
        'top': '50%' 
       }, 200); 
       $scope.loadpantone = function loadpantone(){ 
        border(0); 
        $scope.template = $scope.pantonesAbout[0].url; 
        $('.top_left_logo.white img').css('position', 'fixed'); 
       }; 
       $scope.$watch('$includeContentLoaded', function(){ 
        $('').focus(); 
       }); 
     } 
    }; 
    }); 

контроллер:

'use strict'; 
angular.module('bawdApp') 
    .controller('AboutCtrl', function ($scope) { 
    $scope.pantonesAbout = [ 
      {name:'Pantone intro', url:'views/pantone_about.html'}, 
      {name:'Pantone one', url:'views/about_patone_one.html'}, 
      {name:'Pantone two', url:'views/about_patone_two.html'}, 
      {name:'Pantone three', url:'views/about_patone_three.html'}, 
      {name:'Pantone four', url:'views/about_patone_four.html'}, 
      {name:'Pantone five', url:'views/about_patone_five.html'}, 

     ]; 
    $scope.pantoneconter = 0; 
}); 

ответ

8

события, которые вы ищете, испускаются. Это означает, что вы должны слушать $on:

$scope.$on('$includeContentLoaded', function(){ 
    console.log(arguments); 
}); 
+0

Где я должен их слушать? – vimes1984

+0

@ vimes1984 место, которое вы пытаетесь прослушать (например, ваша директива), в порядке. Просто замените $ watch на $ on. – michael

+0

отлично работает! – vimes1984

Смежные вопросы