1
我正在學習AngularJS。ng-transclude替換內容而不是追加
我經歷了這個video,這裏顯示了將ng-transclude
放在指令模板的標籤上,會將已經存在的DOM東西附加在這個標籤中。
代碼:
<html ng-app="myApp">
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
</head>
<body ng-controller="AppCtrl">
<panel>
<button>Click Me</button>
</panel>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.12/angular.min.js"></script>
<script>
var app = angular.module('myApp', []);
app.controller('AppCtrl', function() {
});
app.directive('panel', function() { //can return a function (link) or an object
return {
restrict: 'E',
transclude: true,
template: '<span> This is my custom span</span><div class="panel" ng-transclude>this is my div</div><span>Another span follows</span>'
}
});
</script>
</body>
</html>
這裏的fiddle,證明了問題。
感謝API鏈接 –
有沒有解決辦法? – rakslice
使用一個跨越功能 – Lloyd