如何在指令中使用$ emit

时间:2015-05-04 05:53:26

标签: javascript javascript-events angularjs-directive

<span class="tag-cross pointer" ng-click="Delete($index,selecteditemslist)">x</span>

这是我的指令html。我有三个删除功能,但删除一个项目时,所有三个都被删除。

这是我的删除功能。

scope.Delete = function (index, selecteditemslist) {

    scope.selectedIndex = index;

    scope.$emit('removeOrg', {
        index: index
    });

    scope.$emit('removeRecipient', {
        index: index,
        type: 'orgs',
        selecteditemslist: selecteditemslist
    });
    scope.$emit('removeRecipient', {
        index: index,
        type: 'people',
        selecteditemslist: selecteditemslist
    });
};

这是我的控制器

$scope.$on('removeRecipient', function (event, args) {
    $scope.index = args.index;
    $scope.selecteditemslist = args.selecteditemslist;
    console.info($scope.index);
    console.info($scope.selecteditemslist);
    $scope.type = args.type;
    switch ($scope.type) {
        case "orgs":
            $scope.RemoveRolesDetach('detachOrg', $scope.selecteditemslist);
            $scope.recipientsOrg.splice($scope.index, 1);
            $scope.displayOrgs.splice($scope.index, 1);
            $scope.recipientsOrgIdArr.splice($scope.index, 1);
            break;
        case "people":
            $scope.RemoveRolesDetach('detachUser', $scope.selecteditemslist);
            $scope.recipientsPeople.splice($scope.index, 1);
            $scope.displayPeople.splice($scope.index, 1);

            $scope.recipientsPeopleIdArr.splice($scope.index, 1);
            break;
    }

});

如何解决这个问题,当我点击一个项目,那个特殊项目只应该删除plss帮我解决这个问题

提前致谢

0 个答案:

没有答案