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 9158255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:12:16+00:00 2026-06-17T13:12:16+00:00

I want to create a list with custom behavior when it’s content changes. I

  • 0

I want to create a list with custom behavior when it’s content changes. I try to create a directive for this but I get a bit lost with how to combine the ng-transclude with the ng-repeat directive. Can somebody put me on track?

Html:

<div ng-app="myApp">
  <div ng-controller="ctrl">
    <mylist items="myItem in items">
       <span class="etc">{{myItem}}</span>
    </mylist>
  </div>
</div>

Javascript:

angular.module('myApp', [])    

.controller('ctrl', function ($scope) {
  $scope.items = ['one', 'two', 'three'];
})    

.directive('mylist', function () {
  return {
    restrict:'E',
    transclude: 'element',
    replace: true,
    scope: true,
    template: [
      '<ul>',
        '<li ng-repeat="WhatGoesHere in items" ng-transclude></li>',
      '</ul>'
    ].join(''),
    link: function (scope, element, attr) {
      var parts = attr.items.split(' in ');
      var itemPart = parts[0];
      var itemsPart = parts[1];
      scope.$watch(itemsPart, function (value) {
        scope.items = value; 
      });      
    }
  }
});

I’ve got part of this somewhat working here

EDIT:

Criteria:

  • The template of the item must be defined in the view, not in the directive and it must have access to an item property in a child scope. Ideally I want to define this like it is done in the ng-repeat directive
  • The directive must have access to the list so I can set proper watches and change things. If possible I would like to have easy access to the generated DOM items (I can also do it with element[0].querySelectorAll('ul>li') or something, It only has to work on Chrome).
  • If possible I would like to reuse the logic in the ng-repeat directive because it does already do a lot of what I want. Preferably I don’t want to copy the code. I just want to augment its behavior, not change it
  • 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-17T13:12:17+00:00Added an answer on June 17, 2026 at 1:12 pm

    Solved the problem myself:

    I am able to do it in the compile step (jsfiddle) by adding the ng-repeat attribute when the template is compiled and feeding it the content of my attribute.

    Html:

    <div ng-app="myApp">
      <div ng-controller="ctrl">
        <mylist element="myItem in items">{{myItem}}</mylist>
      </div>
    </div>
    

    Javascript:

    var myApp = angular.module('myApp', [])
    
    .controller('ctrl', function ($scope) {
      $scope.items = ['one', 'two', 'three'];
    })
    
    .directive('mylist', function ($parse) {
      return {
        restrict:'E',
        transclude: 'element',
        replace: true,
        scope: true,
        template: [
          '<ul>',
          '<li ng-transclude></li>',
          '</ul>'
        ].join(''),
        compile: function (tElement, tAttrs, transclude) {
          var rpt = document.createAttribute('ng-repeat');
          rpt.nodeValue = tAttrs.element;
          tElement[0].children[0].attributes.setNamedItem(rpt);
          return function (scope, element, attr) {
            var rhs = attr.element.split(' in ')[1];
            scope.items = $parse(rhs)(scope);
            console.log(scope.items);
          }        
        }
      }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a list view custom like this link : http://sites.google.com/site/androideyecontact/_/rsrc/1238086823282/Home/android-eye-contact-lite/eye_contact-list_view_3.png?height=420&width=279 so
I want to create a custom list in Flex for an interface prototype. The
I want to create a custom adapter for my list view. Is there any
I want to create a dropdown list in sugarcrm custom module and auto populate
I want to create a Custom List which will contain not only a single
I want to create a web method that accepts a List of custom objects
I want to create a custom list item. Basically it should 3 areas in
I want to create a custom IconItemRenderer for List, which looks something similar to
I want to create custom action in c# code for sharepoint list. I am
I am new in ubuntu 12.04 LTS . I want to create list file

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.