I'm creating an application where I'd like to load my modules via ajax. This application uses AngularJS to handle each module and these are injected into my DOM using Jquery, as in the example below:
EDIT - (as requested by @EduardoBinoto)
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0-rc.0/angular.min.js"></script><scriptsrc="https://code.jquery.com/jquery-2.1.4.min.js"></script>
</head>
<body ng-app="app">
<section name="foo" ng-controller="fooCtrl">
<button ng-click="bar()">my name is foo</button>
</section>
<script>
angular.module('app',[])
.controller('fooCtrl', ['$scope','$http', '$compile', function($scope, $http, $compile) {
$scope.bar = function(){
//simulação de requisição $http que retornou um módulo
var ajaxResponse =
'<section name="bar" ng-controller="barCtrl">'+
'<button ng-click="helloWorld()">hello world</button>'+
'</section>';
//inserção do conteúdo no body através do jQuery
$('body').append(ajaxResponse);
//compilação do novo controller
$compile($('body'),$scope);
};
}])
.controller('barCtrl', ['$scope', function($scope) {
$scope.helloWorld = function(){ alert('Hello World!!!'); };
}])
;
</script>
</body>
</html>
I need to know how I can make angular see this new module after inserting through jquery.
NOTE: I searched for various content on the internet and everyone says I need to run $scope.$apply
or $scope.$digest
but I could not understand in any of the examples I found how to actually use this in this situation.