Hi all, I'm new so greetings! I'm trying to create some dynamic HTML using directives. A simple case worked fine in the case of a single directive but now I'm trying to get a little fancier and I'm not sure how this should work.
Each of the directives below will need to apply ng-model bindings in the elements they create to whatever controller is assigned to the page they are on. Looking at the code below, picture an HTML page with some existing content, which then has an element like this defined at the bottom of it: <div directiveOne></div> I had directiveOne compile and append additional elements to the page, and that worked. What I want to do now is to have directiveOne compile the same elements to the page, plus an additional one that itself is assigned a directive. When expanded out, it should end up looking something like this (this is just an example): <div directiveOne> <input type='text'/> <div directiveTwo> <select> <option>Option</option> </select> </div></div> The reason for the two directives is that there will be some code executed in there to figure out what the elements should actually look like. Ultimately I want directiveOne to make use of a series of little directives and not just directiveTwo. As of right now, here are the two directives, pared down for (I hope) clarity: angular.module('myApp').directive('directiveOne', function ($compile) { return { restrict: 'EAC', scope: '=', templateUrl: '/basePage.html', compile: function(element, attr) { var jsonObj = { test: 'TestData' }; return function(scope, element, attr) { var elem = "<div directiveTwo='"+jsonObj+"'></div>"; $compile(elem)(scope); element.append(elem); } } };}); angular.module('myApp').directive('directiveTwo', function ($compile) { return { restrict: 'EAC', scope: '=', templateUrl: '/subPage.html', compile: function(element, attr) { return function(scope, element, attr) { // Possibly make changes to subPage.html // before returning var elem = "<input ng-model='scopedControllerVar'>"; $compile(elem)(scope); element.append(elem); } } };}); To a certain degree this works in that if I inspect the HTML afterwards I see this: <div directiveOne> <div directiveTwo="[object Object]"></div></div> But the code inside directiveTwo was never executed, and so the div is empty. Is there a way to do this? -- You received this message because you are subscribed to the Google Groups "Angular and AngularJS discussion" group. To unsubscribe from this group and stop receiving emails from it, send an email to angular+unsubscr...@googlegroups.com. To post to this group, send email to angular@googlegroups.com. Visit this group at https://groups.google.com/group/angular. For more options, visit https://groups.google.com/d/optout.