我正在实施一个navigation
指令,该指令应该a
为每个导航项包含元素:
<navigation title="My Web Page">
<a href="#">Home</a>
<a href="#">About</a>
</navigation>
我如何才能访问这些锚点?访问element
's 的孩子link()
只返回模板的孩子,而不是我正在寻找的 'a'。
.directive('navigation', function () {
return {
template: template,
restrict: 'E',
replace: 'true',
scope: {
title: '@'
},
link: function postLink(scope, element, attrs) {
// This only looks in the directive's template
console.log($(element).find('a'));
}
};
});
我错过了什么?我期待在指令的范围内附加一组锚点,并在模板中遍历它们。