我想获取点击使用指令的参数。我想要获取点击事件中的孩子数据来检查是否有孩子。将参数传递给角度指令点击
.....
HTML
div ng-app="treeApp">
<ul>
<treeparent></treeparent>
</ul>
JS
(function() {
var treeApp = angular.module('treeApp', []);
treeApp.directive('treeparent', function() {
return {
restrict: 'E',
template: "<button addchild child='m'>ajith</button><div id='new'></div>"
}
});
treeApp.directive('addchild', function ($compile) {
return {
scope: {
'child':'='
},
link: function (scope, element, attrs) {
debugger;
element.bind("click", function (scope,attrs) {
debugger;
//here i want to get hild ie 'm'
angular.element(document.getElementById('new')).append("<div><button button class='btn btn-default'>new one</button></div>");
});
}
}
});
})();
plz帮助我
问题是什么? 'scope.child'不起作用? –
是scode.child未定义 – Ajith
它将是'scope.child'。另外**删除**这个'angular.element(document.getElementById('new'))。append(“
”);' - 直到你在完全错误的方向上走得太远。 – dfsq