2014-02-09 16 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替換爲$即可。 – michael

+0

完美的作品謝謝你! – vimes1984