angular $viewContentLoaded

27 April 2014

$viewContentLoaded

When using angularJS, you can hook up event listeners like onDomReady using

angular.element(document).ready(function () { // ... 

sometimes it's necessary to wait until the view gets loaded to hook up some additional processing that depends on DOM elements present or created after the controller has processed the view, and $viewContentLoaded is intended just for that.

controllers.js

    / Controllers /
    myapp.controller('ProductController', ['$scope', 'ProductService',
      function($scope, ProductService) {
        $scope.products = ProductService.query();
        $scope.featuredProductList = ProductService.featuredlist();
        $scope.orderProp = 'introductionDate';
        $scope.$on('$viewContentLoaded', loadBootstrapUI); /* Example building UI based elements dependent on fetched data
   }]);

comments powered by Disqus