Tôi đang cố gắng hiển thị chỉ thị bên trong một chỉ thị khác (không chắc chắn nếu bộ lặp trong mẫu đang hoạt động) và dường như chỉ xuất dưới dạng văn bản thay vì biên dịch chỉ thị (mã plunker ở đây: http://plnkr.co/edit/IRsNK9)Hiển thị chỉ thị bên trong một chỉ thị khác (trong mẫu lặp)
Bất kỳ ý tưởng nào về cách tôi thực sự có thể làm cho nó hiển thị đúng chỉ dẫn của tôi-dir-one, my-dir-two, dir-ba của tôi bên trong bộ lặp?
index.html
<!doctype html>
<html ng-app="plunker" >
<head>
<meta charset="utf-8">
<title>AngularJS Plunker</title>
<link rel="stylesheet" href="style.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.js"></script>
<script src="app.js"></script>
<script id="partials/addressform.html" type="text/ng-template">
partial of type {{type}}<br>
</script>
</head>
<body>
<div container></div>
<br /><br /><br />
<b>Below is just to test the directives are actually usable outside the repeater</b>
<div my-dir-one></div>
<div my-dir-two></div>
<div my-dir-three></div>
</body>
</html>
app.js
var app = angular.module('plunker', []);
app.directive('container', function() {
return {
restrict: 'A',
scope: {},
replace: true,
template: '<div class="views">' +
' <div class="view" ng-repeat="view in views">' +
' <div {{view.dir}}>{{view.dir}}</div>' +
' </div>' +
'</div>',
link: function (scope, elm) {
scope.views = [
{ dir: 'my-dir-one' },
{ dir: 'my-dir-two' },
{ dir: 'my-dir-three' }
];
}
}
});
app.directive('myDirOne', function() {
return {
restrict: 'A',
scope: {},
replace: true,
template: '<div>This is directive one.</div>'
}
});
app.directive('myDirTwo', function() {
return {
restrict: 'A',
scope: {},
replace: true,
template: '<div>This is directive two.</div>'
}
});
app.directive('myDirThree', function() {
return {
restrict: 'A',
scope: {},
replace: true,
template: '<div>This is directive three.</div>'
}
});
Tôi không tìm thấy bất kỳ tác dụng phụ nào của giải pháp này. Điều đó nói rằng, tôi phát hiện ra rằng nếu bạn đặt trước tất cả các mẫu (sử dụng dịch vụ $ templateCache), thì bạn có thể lấy đi mà không cần tạo một phần tử trình bao bọc. – romiem