I am trying to populate a profile page with a json object in angularjs. I use directives for this. I have a profile directive in which there are child profile directives. A profile section has subnet profiles as children. I need to run the fragment just before angular starts compiling and only after angular has finished rendering the template.
I tried
app.run() $timeout $evalAsync $(document).ready() $scope.$broadcast postLink function
This is the skeleton of my code
var app = angular.module("profile",[]); app.controller("profileController",['$scope',function($scope){ var ctrl = this; }]) .controller("profileSectionController",['$scope',function($scope){ //$scope.$emit('dataloaded'); }]) .directive("profile",[function(){ return { transclude:true, restrict:'EA', replace:true, templateUrl:'/sstatic/angular_templates/de/profile.html', scope:{ person:"=" }, controller:'profileController', compile:function(elem,attrs,transclude){ return { pre : function link(scope,elem,attrs,ctrl){ //angular.element(elem).find(".candidate-name").append(scope.person.name); //$(elem).css({"display":"none"}); }, post : function link(scope,elem,attrs,ctrl){ //angular.element(elem).find(".candidate-name").append(scope.person.name); //$(elem).css({"display":"block"}); } } } } }]) .directive("profileSection",[function(){ return { transclude:true, restrict:'EA', replace:true, require:'^profile', templateUrl:'/sstatic/angular_templates/de/profile-section.html', scope:{ title:"@", right:"=", sub:"=" }, controller:"profileSectionController", compile:function(elem,attrs,transclude){ return { pre : function link(scope,elem,attrs,ctrl){ //angular.element(elem).find(".candidate-name").append(scope.person.name); }, post : function link(scope,elem,attrs,ctrl){ //angular.element(elem).find(".candidate-name").append(scope.person.name); } } } } }]) .directive("profileSub",[function(){ return { transclude:true, restrict:'EA', replace:true, require:'^profile', templateUrl:'/sstatic/angular_templates/de/profile-sub-section.html', scope:{ subsection:"=" }, controller:function(){ }, compile:function(elem,attrs,transclude){ return function link(scope,elem,attrs,ctrl){ //angular.element(elem).find(".candidate-name").append(scope.person.name); } } } }])
However, most of them start after loading the profile, but not after loading its children. I cannot attach it to children, because it works too many times.
This is the expected timeline of events.
Start Render Event Fires Profile Linked Profile Section 1 Linked Profile Sub Section 1 Linked Profile Sub Section 2 Linked Profile Section 2 Linked Profile Sub Section 1 Linked Profile Sub Section 2 Linked Profile Sub Section 3 Linked .... End Render Event Fires
This is how it is happening now.
Start Render Event Fires Profile Linked End Render Event Fires Profile Section 1 Linked Profile Sub Section 1 Linked Profile Sub Section 2 Linked Profile Section 2 Linked Profile Sub Section 1 Linked Profile Sub Section 2 Linked Profile Sub Section 3 Linked ....
I need some way to run the script after each angular load in the DOM.
Please, help. Very much appreciated.