我有这样的条件:
net
真实场景中发生的事情是
对于Eg。 <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>
因为它不是parseInt,这就是它考虑name.value=1200 sal.annual_value=42
。
我如何在AngularJS表达式中42 > 1200
?
答案 0 :(得分:4)
您可以在parseInt
:
ng-if
<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);
};
答案 1 :(得分: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>
答案 2 :(得分:2)
如果您想在视图中使用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>
图。
e.g。
控制器:
public class Test {
int x =10;
public static void main(String[]args)
{
Test t1 = new Test();
System.out.println(t1.x);
}
查看:
<input *ngIf="fieldForm.value.type == 'phone'" pattern="^([0-9]{2}\s?){5}$" type="text" class="form-control" formControlName="field" [(ngModel)]="value">
答案 3 :(得分:1)
您也可以尝试:
<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);
};