2

I have master page which has script for angularJs and a div which acts as a parent div to load the html page which is created using angular.

ParentPage.aspx

<script src="../../Scripts/angular.min.js" type="text/javascript"></script>
<!-- Controller For Angular Page -->
<script src="../../Scripts/Controller/PartialRegistrationController.js"  type="text/javascript"></script>

<script type="text/javascript">
    var app = angular.module("module", []);

    function partialRegistrationForm() { // Function to Initiate load call      
        $('#divFullRegistration').load('../RegistrationPages/PartialRegistration.htm', function (data) {
            console.log(data);
        });
</script>

<div id="divPopupRegistration" class="RegistrationPopup hide" style="overflow: hidden;z-index: 999" ng-app="module">
    <div id="divFullRegistration" class="Full hide">
    </div>
</div>

PartialRegistration.htm

<head>
    <title></title>
    </head>
<body ng-cloak>
    <div ng-controller="partialcontroller" id="parentDiv" ng-init="init()">
        <div class="registrationBg" runat="server" id="PartialRegistration">

        // Some HTML

        </div>
    </div>
</body>

I have some angular textbox and drop down which gets data from server. I can see empty dropdown in html page.

It works When i put <script type="text/javascript" src="../Scripts/angular.min.js"></script> in PartialRegistration.htm

But angular script is already loaded in ParentPage.aspx, so why this issue is coming ?

6
  • call your partialRegistrationForm func in your angular app.run function. Commented Mar 26, 2015 at 13:17
  • @YOU any code snippet ? Commented Mar 26, 2015 at 13:20
  • app.run(function(){ ............ }); Commented Mar 26, 2015 at 13:22
  • It sounds like you really want a directive called partial-registration that uses PartialRegistration.htm as its template. If you only want to load after something has happened in scope, you can use ng-if for that. Commented Mar 26, 2015 at 13:22
  • why don't bind load event from directive on that divFullRegistration element. Commented Mar 26, 2015 at 13:27

2 Answers 2

4

The problem is that angular is not notified that anything just happened. You must create a directive or use the $compile service and pass any $scope before adding the template

$compile(html)($scope);
Sign up to request clarification or add additional context in comments.

1 Comment

This solution worked perfectly for me. I wrapped my jQuery in this like so: $compile($('#profile-builder').html(resp.data.html))($scope);.
1

I believe you should bind event using directive rather than using jQuery code

Markup

<div id="divFullRegistration" class="Full hide" my-directive></div>

Directive

app.directive('myDirective', function(){
  return {
    restrict: 'AE',
    compile: function(element, attrs){
      //here your all jQuery code will lie to ensure binding
      element.load('../RegistrationPages/PartialRegistration.htm', function (data) {
        console.log(data);
      });
    }
  }
});

Comments

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.