I am new to AngularJS and I cannot get ng-repeat to work when embedded in a directive as follows
<settings-widget>
<ul class="ul-border">
<li class="box" ng-repeat="item in list">{{item}}</li>
</ul>
</settings-widget>
app.directive("settingsWidget", function ($compile, $timeout) {
return {
restrict: "E",
replace: "true",
scope: { },
transclude: true,
templateUrl: "/Settings.html",
compile: function (element, attrs, transclude) {
return function (scope) {
transclude(scope, function (clone) {
var html = angular.element("<div>").append(clone).html();
scope.template = html;
});
};
},
controller: ['$scope', '$element', '$attrs', '$rootScope', function ($scope, $element, $attrs, $rootScope) {
$scope.list = ['item1', 'item2'];
}]
};
});
Settings.html
<div>
<form id="settingsForm" name="settingsForm" novalidate ng-submit="save(settingsForm)" ng-model-options="{ allowInvalid: true}">
<div compile="{{template}}"></div>
</form>
</div>
for some reason when I run my app <li> tags are not being created.
Could someone please help me out?
1. Normal transclusion (passed html uses parent scope): You define
listin parent controller!2. No transclusion (passed html uses directive scope):
2. Transclusion+ (passed html want to use both directive and parent scopes): This one seems to be tricky and I never actually did that, I guess quite easy way is using
$parentref cause you dont have thiscompilemanual calls: