如何用jqlite以角度抓取元素的attr数据?
问题描述:
如何以jqlite的角度抓取元素的attr数据?如何用jqlite以角度抓取元素的attr数据?
HTML,
<button ng-click="loadForm($event)" href="form.php">Load Directive Form</button>
<div data-my-form></div>
角,
app.directive('myForm', function() {
return {
controller:function($scope){
$scope.isLoaded = false;
$scope.loadForm = function(e){
console.log(e.target.attr('href')); // error
var form = e.target.attr('href'); // error
$scope.isLoaded = true;
}
},
template: '<div><div ng-if="isLoaded" ng-include="'+ form +'" ></div></div>',
link:function(scope, element) {
}
}
});
我得到这个错误,
TypeError: e.target.attr is not a function
什么想法?
使用'e.target.href'或'e.target.getAttribute( 'href' 属性)',这取决于是否你想要绝对或相对的链接。我仍然想知道为什么将_href_属性分配给非链接元素。 – raina77ow 2014-12-13 09:10:21
我得到这个错误'错误:[$ parse:syntax]语法错误:在[HTMLDivElement]]开始的表达式[[object HTMLDivElement]]的第9列处出现[Token'HTMLDivElement'是意外的,期待[]]' – laukok 2014-12-13 09:13:25
' form'变量定义为控制器函数的本地变量,但您尝试在模板中使用它。 – raina77ow 2014-12-13 09:16:03