如何使用tags-input angular js隐藏div

时间:2017-04-06 04:52:32

标签: angularjs input tags

我希望使用tags-input在每次删除标记时隐藏div。看一下截图。

enter image description here

现在当我点击2017年4月的十字按钮时,我需要隐藏2017年4月的div 这是html

<div ng-show='monthlyReportForm' >
<form name="monthlyReportFormPage" role="form" novalidate>
    <div role="tabpanel" class="tab-pane top-o-border">
        <div class="row">
            <div class="col-md-4">
                <div asterick class="form-group" ng-class="{'form-group has-success': !error['enhancement_name'] && (submitted), 'form-group has-error': (error['enhancement_name']) && (submitted)}">
                    <label for="enhancementName">Enhancement Name</label>
                    <input type="hidden" name="enhancementId" ng-model="data.enhancementId" value="">
                    <input type="text" name="enhancementName" id="enhancementName" class="form-control" placeholder="Enhancement Name" ng-model="data.enhancementName" ng-required="true" value="">
                    <span class="er-block" ng-show="monthlyReportFormPage.enhancementName.$touched && monthlyReportFormPage.enhancementName.$error.required">Please provide Enhancement Name.</span>
                    <span ng-show="error.enhancement_name" class="er-block">{{error.enhancement_name}}</span>
                </div>
            </div>    
            <div class="col-md-4">
                <div asterick class="form-group" ng-class="{'form-group has-success': !error['months'] && (submitted), 'form-group has-error': (error['months']) && (submitted)}">
                    <label for="months">Months</label>
                    <tags-input ng-model="monthTags" on-tag-removed="removeDiv($tag)"  ng-required="true"></tags-input>
                    <span class="er-block" ng-show="monthlyReportFormPage.months.$touched && monthlyReportFormPage.months.$error.required">Please select months.</span>
                    <span ng-show="error.months" class="er-block">{{error.months}}</span>
                </div>
            </div>
            <div class="pull-right">
                <input type="hidden" name="enhancementId" id="enhancementId" class="form-control" ng-model="data.enhancementId" value="">
                <input type="hidden" name="id" id="id" class="form-control" ng-model="data.id" value="">
                <button class="btn btn-primary" ng-disabled="monthlyReportFormPage.$invalid" ng-click="addMonthlyReport()">{{buttonText}}</button>
            </div>
        </div>
    </div>
    <div  role="tabpanel" class="tab-pane month-reports" ng-repeat="resource_type_efforts in data.resource_type">
        <span class="tab-pane-months">{{data.months[$index]}}</span>
        <div class="row" ng-repeat="resourceTypeMonthly in data.resourceTypeMonthly">
            <div class="col-md-4">
                <div asterick class="form-group" ng-class="{'form-group has-success': !error['resourceType'] && (submitted), 'form-group has-error': (error['resourceType']) && (submitted)}"> 
                    <label for="resourceType">Resource Type</label>
                    <input type="text" name="resourceType" id="resourceType" ng-model="resourceTypeMonthly" class="form-control" ng-required="true" ng-disabled="isDisabled" >
                    <span class="er-block" ng-show="monthlyReportFormPage.resourceType.$touched && monthlyReportFormPage.resourceType.$error.required">Please provide Resource type.</span>
                    <span ng-show="error.resource_type1" class="er-block">{{error.resource_type1}}</span>
                </div>
            </div>
            <div class="col-md-3">
                <label for="efforts">Efforts (in hours)</label>
                <input type="text" name="efforts" id="efforts" class="form-control" ng-model="data.efforts[$parent.$index][$index]"  value="">
            </div>
        </div>

    </div>
</form>
</div>

我使用tags-input将月份显示为标签。这是标签输入库tags-inputdemo

的链接

请建议回答。对于像我这样的新手来说,它会非常有用。

2 个答案:

答案 0 :(得分:1)

 <label for="months">Months</label>
     <tags-input ng-model="monthTags" on-tag-removed="removeDiv($tag)"  ng-required="true" ng-if="status"></tags-input>

在控制器中:

$scope.removeDiv = function() {
   $scope.status = false; //update status value false
}

第二种方法:

你可以使用手表

答案 1 :(得分:0)

您已使用on-tag-removed并调用方法removeDiv($ tag)。因此,在此方法中,取一个布尔变量,并在调用此方法时将其设为false。使用ng-show指令使用该变量来显示或隐藏下面的div。