为什么在使用隔离范围时不呈现包含/子元素。怀疑父级尚未渲染,我尝试添加一个 $timeout,仍然没有运气。如果我通过注释掉隔离范围
scope: {},
有用。做什么使它工作,我需要隔离范围并渲染包含的元素。
代码:http ://plnkr.co/edit/ZEwj9z?p=preview
'use strict';
var app = angular.module('Directives', []);
app.controller('MainCtrl', function ($scope) {
$scope.data = [{id:1}, {id:2}, {id:3}];
});
app.directive('test', function ($timeout) {
return {
restrict: 'A',
scope: {}, //if it is commented out, li would render
link: function (scope, elm, attrs) {
console.log('Inside link..');
}
};
});
模板
<div ng-controller="MainCtrl">
<ul test>
<li ng-repeat="d in data"> {{d}} </li>
</ul>
</div>