1

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
  • anyone who knows why this is not worked ,but when we use ng-include it is worked? Commented May 13, 2016 at 8:35

1 Answer 1

1

You can use the ngInclude directive for that:

<div  ng-controller="loginCtrl">
    <div ng-include="'header.html'"></div>
</div>
Sign up to request clarification or add additional context in comments.

2 Comments

thanks~ i have studied and one more is ng-include should use as "<div ng-include src=" ' header.html' "> </div>
@vincent Oh yes, sorry, made a typo

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.