Reputation: 118
I have 2 applications, an angular app and a jquery app. I want to load my angular app with jQuery. This is my code (really simple) :
index.html
<html>
<head>
<title></title>
<script src="https://code.jquery.com/jquery-3.0.0.min.js" integrity="sha256-JmvOoLtYsmqlsWxa7mDSLMwa6dZ9rrIdtrrVYRnDRH0=" crossorigin="anonymous"></script>
</head>
<body>
<div id="div1"></div>
<script>
$("#div1").load("public/angular.html");//load angular app
</script>
</body>
</html>
public/angular.html
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
<script src="public/app.js">
</head>
<body ng-controller="MyController">
<h1>{{message}}</h1>
</body>
</html>
public/app.js
angular.module("myApp", []);
angular.module("myApp").controller('AppController', function($scope){
$scope.message = "Hi everyone !";
});
Is it posible to do it ? Is it a right way to do it ?
Thx for reply !
Upvotes: 1
Views: 247
Reputation: 118
Thanks Abdou, you're right ! That was the answer !
index.html
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="https://code.jquery.com/jquery-3.0.0.min.js" integrity="sha256-JmvOoLtYsmqlsWxa7mDSLMwa6dZ9rrIdtrrVYRnDRH0=" crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
</head>
<body>
<div id="div1"></div>
<script>
$("#div1").load("public/angular.html");//load angular app
</script>
</body>
</html>
public/angular.html
<html>
<body>
<div ng-controller="MyController">
Hello {{greetMe}}!
</div>
<script>
angular.module('myApp', []).controller('MyController', ['$scope', function ($scope) {
$scope.greetMe = 'World';
}]);
angular.element(document).ready(function() {
angular.bootstrap(document, ['myApp']);
});
</script>
</body>
</html>
Upvotes: 1