Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9040633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T10:02:23+00:00 2026-06-16T10:02:23+00:00

I have the following code: <div ng-app=myApp ng-controller=AngularCtrl> <a href=# id=click_btn>Click here</a> </div> <script>

  • 0

I have the following code:

<div ng-app="myApp" ng-controller="AngularCtrl">
  <a href="#" id="click_btn">Click here</a>
</div>
<script>
 jQuery("#click_btn").click(function(){
  jQuery(this).replaceWith('<p>Hello {{student.name}}</p><div my-repeater></div>');
 });
</script>​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​

Here is my angular code:

var myApp = angular.module('myApp',[]);

myApp.directive('myRepeater', function() {
 return {
    restrict: 'A',        
    link: function(scope, element, attrs) {
        var myTemplate = "<div>{{rating}}</div>";
        for(var i=0;i<scope.items.length;i++)
        {
            var myItem = scope.items[i];                    
            var text = myTemplate.replace("{{rating}}",myItem.rating);
            element.append(text);
        }
    }
 };
}); 

function AngularCtrl($scope) {
  $scope.student = {id: 1, name: 'John'};
  $scope.items = [{id: 1, ratings: 10}, {id: 2, ratings: 20}];
} 

Here, whenever i click on the button, the element is just getting replaced and not evaluated. I tried with “angular.bootstrap(document);” after document is ready.

But that just evaluates the angular objects. But still the custom directive “my-repeater” is not getting evaluated. Any help on how can i get this done?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T10:02:24+00:00Added an answer on June 16, 2026 at 10:02 am

    First of all, I suppose this is test code, since angular has ng-repeat, which fits your needs.

    There are several issues with your code:

    1) You shouldn’t use myTemplate.replace, but use the $compile service. Inject the $compile service into your directive (add as function param) and use it:

    var text = $compile(myTemplate)(scope);
    

    2) Items on the controller will not by accessible in your directive. Add it as a value to your my-repeater attribute:

    <div my-repeater='{{items}}'>
    

    In your directive you need to evaluate my-repeater:

    var items = scope.$eval(attrs.myRepeater);
    

    3) jQuery(this).replaceWith will not kickoff angular, since it it out of its scope. You need to do it manually by using scope.$apply. But is better to add the click event in the directive link function:

    link: function(scope, element, attrs) {
            element.on('click', function() {   
               ...
               scope.$apply();
            });
    

    Edit: Here is a working example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code which <a href=#example id=showtext>view text</a> $(#showtext).click (function () {
I have the following code: <div id=content> <?php if(count($app->getMessageQueue())) { ?> <jdoc:include type=message />
I have the following code to get user data form facebook <div id=fb-root></div> <script>
I have the following code: index.html <HTML> <HEAD> <TITLE>My App</TITLE> <LINK rel=stylesheet type=text/css href=style.css>
I have the following jQuery code (I have changed names of div and functions,
i have following code to show div on page <div id=all_users> <div id=user11 userid=11
I have following code <div id=main> <div id=one> </div> <div id=two> </div> <div id=three>
I have following PHP code $val=<div id=user.$row['cid']. userid=.$row['cid']. class=innertxt><img src=images/images.jpg width=50 height=50><strong>.$uname.</strong><ul> <li>Email: .$row['cemail'].</li>
I have the following code below however am confused as to why the div
I have the following code: <div id=header> <h1>HEADER TEXT</h1> <div id=members> <form action= method=post>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.