如何使用 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
有任何想法吗?