0
基本上我有2个自定义指令,每个指令都有自己的模板。我需要的是将其中一个模板插入其他模板。我也读过关于跨越的内容,但是不能把我的头包裹起来。任何想法都会有很大的帮助!使用1指令模板到另一指令模板
基本上我有2个自定义指令,每个指令都有自己的模板。我需要的是将其中一个模板插入其他模板。我也读过关于跨越的内容,但是不能把我的头包裹起来。任何想法都会有很大的帮助!使用1指令模板到另一指令模板
从AngularJS网站,一个例子:
<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" aria-label="title"> <br/>
<textarea ng-model="text" aria-label="text"></textarea> <br/>
<pane title="{{title}}"><span>{{text}}</span></pane>
</div>
你必须创建自定义指令,在这种情况下,“窗格”,从内angular.module。当你这样做的时候,指令就存在于应该是你的应用程序的模块中,你可以自由地使用它,因为它是从指令例子返回的。在这种情况下,该示例使用“窗格”指令,并将transcluded模板关联到它。