©
本文档使用
php.cn手册 发布
指令用于标记紧挨着的使用嵌入式的父指令中包含的DOM的插入点。
在内容插入前,这个指令所在元素的任何已存在内容会被清除。
<ng-transclude>
...
</ng-transclude>
<ANY>
...
</ANY>
<ANY class=""> ... </ANY>
<script>
angular.module('transcludeExample', [])
.Directive('pane', Function(){
return {
restrict: 'E',
transclude: true,
scope: { title:'@' },
template: '<div style="border: 1px solid black;">' +
'<div style="background-color: gray">{{title}}</div>' +
'<ng-transclude></ng-transclude>' +
'</div>'
};
})
.controller('ExampleController', ['$scope', Function($scope) {
$scope.title = 'Lorem Ipsum';
$scope.text = 'Neque porro quisquam est qui dolorem ipsum quia dolor...';
}]);
</script>
<div ng-controller="ExampleController">
<input ng-model="title"><br>
<textarea ng-model="text"></textarea> <br/>
<pane title="{{title}}">{{text}}</pane>
</div>
it('should have transcluded', Function() {
var titleElement = element(by.model('title'));
titleElement.clear();
titleElement.sendKeys('TITLE');
var textElement = element(by.model('text'));
textElement.clear();
textElement.sendKeys('TEXT');
expect(element(by.binding('title')).getText()).toEqual('TITLE');
expect(element(by.binding('text')).getText()).toEqual('TEXT');});