2017-01-13 32 views
0

我有一个带有用户数据表单的角度模板。角度ng显示不反映条件的值

<div class="personal-details" ng-show="showInvoiceFields()"> 
    <!-- input fields here... --> 
</div> 

我在当前用户有“发票的作用”,或者如果产品需要发票,则返回true范围的功能showInvoiceFields():如姓名和地址某些字段只有当用户需要发票证明。

$scope['showInvoiceFields'] = function() { 
    console.log('hasInvoiceRole: ' + $scope['hasInvoiceRole']); 
    console.log('product:'); 
    console.log($scope['product']); 
    return $scope['hasInvoiceRole'] || $scope['product'].needsInvoice; 
    }; 

表单的这一部分最初是隐藏的,直到从下拉列表中选择一个产品为止。最初,我在控制台看这一点,因为用户没有发票的作用:

hasInvoiceRole: false 
product needs invoice: 
undefined 
undefined 

当我选择需要发票的产物,我读:

hasInvoiceRole: false 
product needs invoice: 
{... a ver big object..., needsInvoice: true, ...} 

然而字段不显示。这只发生在生产中。也许有关于导致问题的缩小代码的具体内容?

回答

0

所以我在我的代码中发现了这个问题。罪魁祸首在于:

$scope['product'].needsInvoice 

当角度缩小代码时,它可能会重命名所有变量,包括“needsInvoice”。为了解决这个问题,我只是把这条线改为:

$scope['product']['needsInvoice']