how to inject an html element with angular directives using jquery?

164 Views Asked by At

I want to inject one HTML element which has been announced with angular directives. With jquery. but the application is not working.

<!doctype html>
<html>
    <head>
    <title>test angular</title>
    </head>
<body>
<div id ="header" ng-app="loginApp"></div>
    <script src="js/jquery.js"></script>
    <script src="js/angular.js"></script>
<script>
  $("#header").load("header.html");
  var app=angular.module("loginApp",[]);
  app.controller("loginCtrl",function(){
    $scope.data="mydata";
  });
</script>
</body>
</html>

and the header.html is :

<div  ng-controller="loginCtrl">
    {{data}}
</div>

but there is no result also no error messages:

enter image description here

1

There are 1 best solutions below

2
On

You can use the ngInclude directive for that:

<div  ng-controller="loginCtrl">
    <div ng-include="'header.html'"></div>
</div>