2017-02-07 4 views
0

でのparseIntへ:私が条件のようなタイプがありますどのようにangularjs表現

<td ng-repeat="sal in name.salaries" 
    ng-if="name.avalue>sal.annual_value"> 
     Value must be less than or equal to Balance Amount 
</td> 

実際のシナリオで起こっするために、例えば

でいただきました。 name.value=1200 sal.annual_value=42 そのparseInt thatsなぜその考慮42 > 1200

AngularJSの表現ではどうすればいいですか?parseInt()

+0

name.avalue NG-場合で、それはあなたの例のようにName.valueにすべきではありませんか。? –

+0

単純な 'Number(name.value)'を使用してください。 –

答えて

4

私はその検証を行うためにスコープの機能を使用します。

{...} 
scope.checkSalaries = function(avalue, annual_value) { 
    return avalue > annual_value; 
} 
{...} 

およびhtml:

<td ng-repeat="sal in name.salaries" 
    ng-if="checkSalaries(name.avalue,sal.annual_value)"> 
     Value must be less than or equal to Balance Amount 
</td> 
+0

その作業。ありがとうmann。 @MihailStancescu – Mohammed

4

あなたのng-ifparseIntを使用することができます。

<td 
    ng-repeat="sal in name.salaries" 
    ng-if="parseInt(name.avalue)>parseInt(sal.annual_value)"> 
     Value must be less than or equal to Balance Amount 
</td> 

それとも、あなたのコントローラでこれを確認するための関数を作成することができます。

<td 
    ng-repeat="sal in name.salaries" 
    ng-if="isGreater(name.avalue, sal.annual_value)"> 
     Value must be less than or equal to Balance Amount 
</td> 

$scope.isGreater = function(val1, val2) { 
    return parseInt(val1) > parseInt(val2); 
}; 
+0

2つ目の@ Magicpro.frが動作しています – Mohammed

1

あなたも試すことができます:あなたはビューでparseIntメソッドを使用したい場合は

<td 
    ng-repeat="sal in name.salaries" 
    ng-show="isGreater(name.avalue, sal.annual_value)"> 
     Value must be less than or equal to Balance Amount 
</td> 

$scope.isGreater = function(val1, val2) { 
    return parseInt(val1) > parseInt(val2); 
}; 
2

は、あなたのコントローラでNumber $の範囲を定義することができますし、ユーザーにそのメソッドparseInt()に建てられましたビューに表示されます。

コントローラー:

$scope.number = Number; 

ビュー:

<td ng-repeat="sal in name.salaries" ng-if="number.parseInt(name.avalue)>number.parseInt(sal.annual_value)"> 
Value must be less than or equal to Balance Amount</td> 
+0

は魅力的に働いた、ありがとう – ganesh