答案 0 :(得分:0)
默认情况下,AngularJS将未初始化的模型视为null
。因此,在您的情况下,a
和b
都是null
。
这就是原因:
null - -null // {{ a -- b }} is {{ a - -b }} actually
将导致0。
答案 1 :(得分:0)
希望这将涵盖您的要求。谢谢。
var app = angular.module('demo', []);
app.controller('mainController', ['$scope',
function($scope) {
$scope.testfunction = function(value) {
return value>0 ?value:'';
} }
]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.22/angular.min.js"></script>
<html ng-app="demo">
<div ng-controller="mainController as mainControl">
<img src="https://angularjs.org/img/AngularJS-large.png" height="50px" weight="50px"/>
<h3>Sum of two Numbers using AngularJS</h3>
<div>
<h3>Using Double Negation</h3>
First Number: <input type="text" ng-model="a" />
Second Number: <input type="text" ng-model="b" />
Sum:<input type="number" value='{{testfunction(a--b)}}' >
</div></div>
</html>