假设您有如下指令。
指令
module.directive('person', function() {
return {
restrict: 'E',
scope: {
header: '='
},
transclude:true,
template: '<div ng-transclude></div>'
};
});
查看
<person>
.....
</person>
我想知道是否有办法知道<person>
中存在被盗的html内容。
感谢。
答案 0 :(得分:1)
使用link function
in指令查找子节点,如下所示
link: function(scope, element, attributes)
{
var count = element.find('div')[0].children.length;
var content = element.find('div')[0];
console.log(content);
console.log("Transcluded html content nodes:"+count);
}
<强> Working Demo 强>
<强> HTML 强>
<div ng-app='myApp' ng-controller="Controller">
<person>
<input type="text" ng-model="user" class="ng-scope ng-pristine ng-valid"/>
<input type="text" ng-model="place" class="ng-scope ng-pristine ng-valid"/>
</person>
</div>
<强>脚本强>
var app = angular.module('myApp', []);
app.directive('person', function() {
return {
restrict: 'E',
scope: {
header: '='
},
transclude:true,
template: '<div ng-transclude></div>',
link: function(scope, element, attributes){
var count = element.find('div')[0].children.length;
var content = element.find('div')[0];
console.log(content);
console.log("Transcluded html content nodes:"+count);
}
};
});
app.controller('Controller', function ($scope) {
});
<强>输出强>