用angularjs写个计算器

效果:效果

代码

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"> http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
</head>
<body>

<div ng-app="myApp" ng-controller="myCtrl">
<input type="number" ng-model="num1">
<select ng-model="num">
 <option value="+">+</option>
 <option value="-">-</option>
 <option value="*">*</option>
 <option value="/">/</option>
</select>
<input type="number" ng-model="num2">
<h1>值为: {{num=="+"?num1+num2:num=="-"?num1-num2:num=="*"?num1*num2:num=="/"?num1/num2:0}}</h1>
</div>

<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
 $scope.num1=1;
 $scope.num2=1;
    $scope.num="+";
});
</script>
</body>
</html>

虚像:

评论 阅读