In controller I get some JSON data using $http or $resource services. Then I write this data in $scope and AngularJS updates HTML structure of the page. My problem is that I
Olivér's answer is good, but has an issue: if you forget to broadcast the event, your javascript will not run whereas your data might have changed. Another solution would be to watch for changes on the scope, for instance:
var tradesInfo = TradesInfo.get({}, function(data) {
console.log(data);
$scope.profile = data.profile;
// ...
});
directive('heightStuff', ['$timeout',
function($timeout) {
return {
scope: {
myData: '='
},
link: function($scope, element, attrs) {
$scope.$watch('myData', function() {
$timeout(function() { // You might need this timeout to be sure its run after DOM render.
element.width()
element.height()
}, 0, false);
})
}
};
}
]);
This way the javascript functions are called every time the data changes without any need for a custom event.