JSFiddle - React, Tailwind, and code Playground

HTML

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.10/angular.js"></script>
  <script type="text/ng-template" id="a.html">
     a.html
  </script>
  
  <script type="text/ng-template" id="b.html">
      <div ng-repeat="itm in data.values">
           <input name='{{itm.name}}'id='{{itm.name}}' ng-model='itm.name' type='text'></input>
      </div>      
  </script>

<div ng-controller="TestController">
    <directive data="data"></directive>
</div>

JavaScript

var myApp = angular.module('myApp', [])
    .controller('TestController', ['$scope', function ($scope) {
        $scope.data = [{ type: "a", values: [{name:"aa"}, {name: "bb"}]},
          { type: "b", values: [{name:"aa"}, {name: "bb"}]}]
}]);   
myApp.directive('directive', function () {
    return {
        scope: {
            data: "=",
        },
        restrict: 'E',
        controller: function ($scope, $element, $attrs) {
            $scope.random = function(){
                $scope.model = $scope.data[Math.floor(Math.random()*$scope.data.length)];
                console.log($scope.model)
            };
        },
         template: '<div><button ng-click="random()">Random</button><sub-directive data="model"></sub-directive></div>'
    };
});


myApp.directive('subDirective', function ($templateCache, $compile) {
    return {    
         scope: {
            data: "=",
        },
        template: '<div></div>',
        restrict: 'E', 
        link: function (scope, element, attrs) {
             scope.$watch('data', function (newVal, oldVal) {
                if (newVal) {
                    var content = angular.element('<span>');
                    content.html($templateCache.get(newVal.type + '.html'));
                    $compile(content.contents())(scope);
                    element.html("");
                    element.append(content);
                 }
             });
        }
    };
});