나는 내 자신의 태그를 만들고 싶다. 부트 스트랩 타입 어 헤드를 사용하고이 요소에 지시문을 추가하고 선택 작업에서 브로드 캐스트를 수신합니다.지시어에서 DOM 요소를 찾아 제거하는 방법은 무엇입니까?
이전에 추가 된 태그 요소를 제거하는 방법을 찾을 수 없습니다. 나는 두 가지 일을 할 수 없다 : id가 알려져 있더라도 my suctom id를 전달하고이 DO 요소를 찾아 제거한다.
제발 도와 드릴까요?
mainApp.directive("tagsManager", ['$compile', function($compile) {
return {
restrict: 'A',
link: function(scope, element, attrs) {
console.log("Tags in directive: " + scope.tags);
scope.$on('tags.new', function(event, tag) {
console.log("New tag is arrived: " + tag.name);
var templ = "<div class=\"btn btn-default\" ng-click=\"tagClick($event)\" id=\"tag.name\">tag.name</div>"
.replace(/tag.name/, tag.name).replace(/tag.name/, tag.name);
var el = angular.element(templ);
el.attr("bind-data", tag);
// $scope.items = teamSharedObj.teams;
$compile(el)(scope);
element.after(el);
});
scope.tagClick = function (tag) {
console.log("Tag: " + tag);
// TODO find a way to get id of this element and rempve it
}
}
}
}])
'$ (this) .attr ("id");'여기서'console.log'는 id를 얻고, 단순히'.remove()'를 사용하여 제거합니다. 일단 당신이 이드를. – rfornal
...'$ (this) .remove()' – rfornal
태그를 표시하는 데'ng-repeat'를 사용하지 않는 것이 어떨까요? 그런 다음 배열 객체에서 태그 객체를 제거하면 각도가 DOM에서 제거됩니다. 당신이 지시어에 가지고있는 코드의 대부분을 필요로하지 않을 것입니다. – charlietfl