[英]AngularJS Error "element.children(...).slideToggle is not a function"
As the title says, whenever I click on an element that is supposed to have a description of what the element is, I get that error.正如标题所说,每当我单击一个应该描述该元素是什么的元素时,我都会收到该错误。 I have tried removing the E
in restrict: 'E'
and replacing it with 'A' and that didn't work.我试过在restrict: 'E'
删除E
restrict: 'E'
并将其替换为 'A' 并且没有用。 I have tried to get my function to work many ways as I can and I can't seem to get it to work.我试图让我的函数以多种方式工作,但我似乎无法让它工作。 it is supposed to show the text in an element when you click on it.当您单击它时,它应该显示元素中的文本。 Could you please help me with this?你能帮我解决这个问题吗?
module.exports = function() {
return {
restrict: 'EA',
templateUrl: 'api.html',
link: function(scope, element) {
//Dom manipulation
element.on("click", function(e) {
element.children(':last-child').slideToggle();
})
}
};
};
element.children(':last-child').slideToggle();
Is empty or undefined, so there is no function slideToggle for it.为空或未定义,因此没有用于它的函数 slideToggle。
Try:尝试:
element.children().last().slideToggle();
or或者
$(this).children().last().slideToggle();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.