简体   繁体   English

为什么ng-if在ng-repeat中不起作用

[英]Why ng-if is not working inside ng-repeat

I cannot properly use my ng-if inside an ng-repeat. 我无法在ng-repeat中正确使用ng-if。 I've updated my AngularJS to the newest version (09/27/2014) and I still can not get it to work right. 我已经将AngularJS更新到最新版本(2014/9/27),但仍然无法正常使用。 I have code that works fine outside of the ng-repeat and I also have code that works inside ng-repeat fine when I ng-if="vm.detail == false". 我的代码可以在ng-repeat之外正常工作,也可以在ng-if =“ vm.detail == false”时在ng-repeat内正常工作。 However ng-if="vm.detail == true" does NOT work. 但是ng-if =“ vm.detail == true”不起作用。 I even have printed the value of vm.detail to the console and it's correct, as it should be. 我什至已经将vm.detail的值打印到了控制台,它是正确的,应该是正确的。 But, the block of code that evaluates ng-if="vm.detail == true" as "true" does NOT execute. 但是,不会执行将ng-if =“ vm.detail == true”评估为“ true”的代码块。 It's nuts. 疯了 Here is my code: 这是我的代码:

                    <th>Division</th>
                    <th>Pool</th>
                    <th>Subpool</th>
                    <th ng-click="sort.predicate = 'ExperienceGroup.RenewalGroup.Name'; sort.reverse = !sort.reverse">
                        RenewalGroup
                    </th>
                    <th>MCH</th>
                    <th ng-click="sort.predicate = 'ContractNumber'; sort.reverse = !sort.reverse">
                        Contract
                    </th>
                    <th ng-click="sort.predicate = 'PlanCode'; sort.reverse = !sort.reverse">
                        PlanCode
                    </th>

                </tr>

                <!--Search By: Mch, Contract Number, Mcp, PlanCode--> 
                <tr ng-if="vm.detail == true">
                    <th>Trust</th>
                    <th>MCH</th> 
                    <th>Contract</th> 
                    <th>Plan Code</th> 
                    <th>Status Date</th> 
                    <th>Status</th> 
                    <th>Effective Date</th> 
                    <th >MCP</th>
                    <th >Rates</th>
                    <th>State Availability</th>
                </tr>

            </thead>
            <tbody>


                <!--Data for MchNumber, ContractNumber, PlanCode Searches-->
                <tr ng-repeat="vm in vm.Mch2Information" ng-if="vm.detail == 'true'">
                    <!--<th>{{vm.CustomerNumber}}</th>-->
                    <td> {{vm.TrusteeCustNum}}</td>
                    <td>{{vm.CustomerNumber}}</td>
                    <td>{{vm.ContractNumber}}</td>
                    <td>{{vm.PlanCode}}</td>
                    <td>{{vm.PlanStatusDate}}</td>
                    <td>{{vm.PlanStatus}}</td>
                    <td> {{vm.PlanEffectiveDate}}</td>
                    <td>{{vm.Mcp}}</td> <!--Not yet implemented-->
                    <td><a href="">Rates</a></td>
                    <td><a href="">State Availability</a></td>

                </tr>



                <!--Data for Division, Pool, Subpool, and RenewalGroup Searches-->
                <tr ng-repeat="plan in vm.plans  
                    | filter: {MchNumber : planFilter.Mch} 
                    | limitTo: vm.pageSize" ng-if="vm.detail == false">

                    <td>{{plan.ExperienceGroup.RenewalGroup.Subpool.Pool.Division.DivisionName}}</td>
                    <td>{{plan.ExperienceGroup.RenewalGroup.Subpool.Pool.PoolName}}</td>
                    <td>{{plan.ExperienceGroup.RenewalGroup.Subpool.SubpoolName}}</td>
                    <td>{{plan.ExperienceGroup.RenewalGroup.RenewalGroupName}}</td>
                    <td><a href="#/Mch/MCH/{{plan.MchNumber}}">{{plan.MchNumber}}</a></td>
                    <td>{{plan.PlanDesign.ContractNumber}}</td>
                    <td>{{plan.PlanDesign.PlanCode}}</td>
                    <td>{{plan.Mcp}}</td>
                  </tr>

And the controller: 和控制器:

    function getPlans(searchParameters)
    {
        vm.loadingPlans = true; vm.search = searchParameters;
        mchService.searchParameters = searchParameters.MchNumber;
        datacontext.getAssignedPlans(searchParameters, vm.pageSize).then(function (plans)
        {
            vm.plans = plans;

      //Compares which columns are being populated for choosing which headings to show
        if (vm.search.MchNumber != null 
            ||vm.search.ContractNumber != null 
            || vm.search.PlanCode != null)
        {
            vm.detail = true;
            vm.test = !vm.test;
            alert("vm.detail is: " + vm.detail)
            //vm.detail = !vm.detail;
            //If users enter JUST a MCH number then display those results
            if (vm.search.ContractNumber == null & vm.search.PlanCode == null)
            {
                vm.getEntityInformation();
            }

        }

        if (vm.search.DivisionName != null
            || vm.search.PoolName != null
            || vm.search.SubpoolName != null
            || vm.search.RenewalGroupName != null)
        {
            vm.detail = false;
            alert("vm.detail is: " + vm.detail);
           // vm.detail = !vm.detail;
        }

            //Sets values to NULL after every search is performed
       vm.search.MchNumber =
       vm.search.ContractNumber =
       vm.search.PlanCode =
       vm.search.DivisionName =
       vm.search.PoolName =
       vm.search.SubpoolName =
       vm.search.RenewalGroupName = null;

        }).finally(function () { vm.loadingPlans = false; });   
    }

Please update that bit. 请更新该位。

<tr ng-repeat="vm in vm.Mch2Information" ng-if="vm.detail == 'true'">
    <!--<th>{{vm.CustomerNumber}}</th>-->
    <td>{{vm.TrusteeCustNum}}</td>
    <td>{{vm.CustomerNumber}}</td>
    <td>{{vm.ContractNumber}}</td>
    <td>{{vm.PlanCode}}</td>
    <td>{{vm.PlanStatusDate}}</td>
    <td>{{vm.PlanStatus}}</td>
    <td>{{vm.PlanEffectiveDate}}</td>
    <td>{{vm.Mcp}}</td>
    <!--Not yet implemented-->
    <td><a href="">Rates</a>
    </td>
    <td><a href="">State Availability</a>
    </td>
</tr>

to : 至 :

<tr ng-repeat="info in vm.Mch2Information" ng-if="vm.detail == 'true'">
    <!--<th>{{vm.CustomerNumber}}</th>-->
    <td>{{info.TrusteeCustNum}}</td>
    <td>{{info.CustomerNumber}}</td>
    <td>{{info.ContractNumber}}</td>
    <td>{{info.PlanCode}}</td>
    <td>{{info.PlanStatusDate}}</td>
    <td>{{info.PlanStatus}}</td>
    <td>{{info.PlanEffectiveDate}}</td>
    <td>{{info.Mcp}}</td>
    <!--Not yet implemented-->
    <td><a href="">Rates</a>
    </td>
    <td><a href="">State Availability</a>
    </td>
</tr>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM