2

I created an web application in javascript and jQuery. Rendered dynamic html page using jQuery .load() method.

File home.html, included angularjs.min.js file. This page having one button "loadUsers". On click handler of the button loading "userList.html" file in a container ("#userContainer") same page.

The userList.html sample content is like below,

<div ng-app>
Enter Your Name: <input type="text" ng-model="txtName" /> <br />
Hello {{txtName}}

On input, the value is not binding with model. Angular is not applied for dynamically loaded template.

Any one guide me how to achieve this?

2
  • 1
    missing value for ng-app to match your main app module name. Also if you are loading that after page load (using ajax for example) you would need to manually bootstrap the angular app. A minimal reproducible example would help. Your explanation of all this is not very descriptive or clear Commented Jul 13, 2019 at 12:54
  • 1
    Thanks for your reply @charlietfl,I tried angular.bootstrap(document, ['myNgApp']); it was working fine. Commented Jul 13, 2019 at 13:01

2 Answers 2

2

The AngularJS framework scans the DOM for the ng-app directive at DOMContentLoaded. If the directive is added later (say after an .ajax call), the directive is ignored.

Any apps added to the DOM after DOMContentLoaded need to be manually bootstrapped:

angular.bootstrap(document, ['myNgApp']);

For more information, see


AngularJS and jQuery can live together if done wisely. In fact the AngularJS framework will use jQuery internally if the jQuery library is loaded before the AngularJS library.

For more information, see - AngularJS angular.element Function API Reference.

Sign up to request clarification or add additional context in comments.

Comments

0

The main question is: Why do you need to use jquery and angular together?!

I think you can move the ng-app to body or html tag. When the content is loaded use $compile service to append $scope to your view. (angular 1.7)

2 Comments

3 years back I created javascript engine with jQuery to render screen, bind device specific events, popup, custom alert, ajax request, ect for single page application. All the screen implemented in javascript design batten achieving MVC. Now am trying to include an angular app in side the engine.
AngularJS and jQuery can live together if done wisely. In fact the AngularJS framework will use jQuery internally if the jQuery library is loaded before the AngularJS library. For more information, see AngularJS angular.element API Reference.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.