在选项卡之间切换后,ng-class表达式的计算结果为false

时间:2018-03-09 01:38:19

标签: javascript angularjs

我正在编写一个代码,在某些条件下应该禁用该按钮。我的按钮(预览值卖方)正在使用data-ng-class,我在其中传递表达式" disabled:currentQuotation.previewValueSellerDisabled"。当页面第一次加载时,此值为true,但只要在页面或选项卡之间切换,按钮就会激活。我将data-ng-class更改为data-ng-disabled,但它无法正常工作。不确定我是否遗漏了某些东西。我调试了响应对象,它包含以下内容。

响应对象: - 消息:"好的" previewdisabled:" true" 响应时间:" 615" 状态:" 1"

当我再次运行时,响应对象没有显示任何内容。我发现响应对象来自这个java代码。

public DataBean checkQuoteBrandCode(DataBean input) {
            DataBean result =  Helper.getResponseTemplate();
            Long quoteid = Long.valueOf(input.getString("quoteid"));
            List<Ctmtcom> comList = manageConfigurationRepo.getAllComponents(quoteid);


    DataBean component = new DataBean();
                for(Ctmtcom ctmtcom: comList){
                    component.setValue("brandcode", ctmtcom.getBrandcode());
                    if(ctmtcom.getBrandcode().equals("26")){
                        result.setValue("previewdisabled",true);
                        return result;
                    }
                }
                result.setValue("previewdisabled",false);
                return result;
            }

我的控制器代码: -

var doLater = function(response){   
    if($scope.currentQuotation.headerData.status == "Value Seller Approved"){
        if(response.previewdisabled=="true"){
            $scope.currentQuotation.previewValueSellerDisabled = true;
            $scope.currentQuotation.acceptValueSellerDisabled = true;
        }else{
            $scope.currentQuotation.previewValueSellerDisabled = false;
            $scope.currentQuotation.acceptValueSellerDisabled = false;
        }
        $scope.previewValueSellerLinkShow = true;
    }else{
        $scope.previewValueSellerLinkShow = false;
    }

我的HTML

<div class="ibm-small" style="float:left;padding-left:35px;padding-top:5px" 
     data-ng-if=" ((appname=='PSAT' && currentQuotation.quoteCustomer.vsmandatory=='Y')  || appname=='PCS' ) && !sp2user && (currentQuote.overViewData.geoCode=='AP' || currentQuotation.overViewData.geoCode=='NA' || (currentQuotation.overViewData.geoCode=='EM' && currentQuotation.detailPricing.useAGOG=='Y' && currentQuotation.detailPricing.vspDeployed=='Y') && currentQuotation.detailPricing.dis=='N')">
    <button type="button" class="btn btn-success" href="" data-ng-click="previewAddendum()" data-ng-class="{disabled:currentQuotation.previewValueSellerDisabled}">
        <svg class="icon icon-eye"><title>Preview value seller offer</title><use xlink:href="#icon-eye"></use></svg>
        <strong translate="Preview_Value_Seller_Offer"></strong>                
    </button>       
</div>

1 个答案:

答案 0 :(得分:0)

您在上面说过,您更改了&#39; ng-class&#39;禁用&#39;

您之前的问题是使用ng-class,请记住,如果表达式为true,ng-class将添加类。它不会自动禁用您的按钮(除非您的班级使用css手动禁用按钮)。

现在问题是我认为你仍然将{disabled:currentQuotation.previewValueSellerDisabled}作为表达式传递,问题很明显。表达本身是错误的,你不需要通过&#34;禁用&#34;你需要做的只是传递变量&#34; currentQuotation.previewValueSellerDisabled&#34;看起来像这样

NG-禁用=&#34; currentQuotation.previewValueSellerDisabled&#34;

但请记住,当你说你改变它时,我只是猜测你传递的数据被禁用了