我在h2标签中有这个文字。我也尝试过输入字段。我不能把这个计算推到这个ng模型。最好的方法是什么?这个分数是在括号内计算的,但我需要它与ng-model一起使用。我知道ng-models适用于选择,输入和文本区域。不知道如何解决这个问题:
<div ng-app ng-controller="LoginController">
<input type="radio" ng-model="score.name1" value="1">
Red
</label><br/>
<label>
<input type="radio" ng-model="score.name2" ng-value="2">
Green
</label><br/>
<label>
<input type="radio" ng-model="score.name3" value="3">
Blue
</label><br/>
<h2 ng-model="score.total">Score: {{ (score.name1 -- score.name2 -- score.name3 / 3 }} </h2>
</div>
&#13;
答案 0 :(得分:0)
试试这段代码。
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myCtrl">
<input type="radio" ng-model="score.name1" ng-value="1"> Red
<br/>
<label>
<input type="radio" ng-model="score.name2" ng-value="2">
Green
<br/>
<label>
<input type="radio" ng-model="score.name3" ng-value="3">
Blue
<br/>
<h2 ng-model="score.total">{{(score.name1--score.name2--score.name3)/3}}</h2>
</div>