[英]Angular. Finding all images in a div
I am trying to find all img tags in a div. 我正在尝试在div中查找所有img标签。 These img tags are in p tags that sit in the div.
这些img标签位于div中的p标签中。 I made a plunkr to see if I could get it working but no joy so far.
我大吃一惊,看看我能否使它工作,但到目前为止还没有喜悦。 If anyone could have a look and point me in the right direction that would be great.
如果有人可以看看并指出正确的方向,那将很棒。
index.html: index.html:
<!DOCTYPE html>
<html ng-app="plunker">
<head>
<meta charset="utf-8" />
<title>AngularJS Plunker</title>
<script>document.write('<base href="' + document.location + '" />');</script>
<link rel="stylesheet" href="style.css" />
<script data-require="angular.js@1.3.x" src="https://code.angularjs.org/1.3.20/angular.js" data-semver="1.3.20"></script>
<script src="app.js"></script>
</head>
<body>
<div >
<p image-append>
<p >
<img src="https://www.petfinder.com/wp-content/uploads/2012/11/140272627-grooming-needs-senior-cat-632x475.jpg" />
</p>
<p>
<img src="http://www.vetprofessionals.com/catprofessional/images/home-cat.jpg" />
</p>
</p>
</div>
app.js: app.js:
var app = angular.module('plunker', []);
app.directive('imageAppend', imageAppend);
/*@ngInject*/
function imageAppend() {
return {
restrict: 'A',
link:function(scope,element,attrs){
console.log("elemnts are ===== ", element.find('img'))
}
};
}
plunkr: http://plnkr.co/edit/W1PWVgtysZ4cOwaIpmbc?p=preview plunkr: http ://plnkr.co/edit/W1PWVgtysZ4cOwaIpmbc?p=preview
Could you please try this code : 您可以尝试以下代码:
var app = angular.module('plunker', []);
app.directive('img', imageAppend);
function imageAppend() {
return {
restrict: 'E',
link: function (scope, element, attrs) {
console.log("elemnts are ===== ", element)
}
};
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.