这是我的代码:
<html ng-app="myApp">
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.8/angular.js"></script>
</head>
<body>
<div ng-controller="Ctrl">
<testel title="{{data.title}}">
<input ng-model="data.title">
<h3>Transclude title: {{title}}</h3>
<h3>Transclude data title: {{data.title}}</h3>
</testel>
</div>
<script>
angular.module('myApp',[])
.controller('Ctrl',function($scope){
$scope.data={};
$scope.data.title="Gas";
})
.directive('testel', function(){
return {
restrict: 'E',
scope: {
title: '@'
},
transclude: true,
templateUrl: "./transclude.html",
link: function(scope, element, attrs, ctrl, transcludeFn) {
console.log(scope.$$nextSibling);
}
}
});
</script>
</body>
</html>
和transclude.html:
<h3>Template title: {{title}}</h3>
<h3>Template data title:{{data.title}}</h3>
<ng-transclude></ng-transclude>
为什么我从console.log(范围。$$ nextSibling)获取null?我正在等待翻译范围。
另外,我如何在控制范围内自行调整翻译范围?
答案 0 :(得分:0)
从Angular 1.3+开始,它是孤立范围的孩子。在此之前,他们是兄弟姐妹。