<select ng-model="currentTimeStartHour" style="width: 33%" ng-change="UpdateTime(this)">
<option ng-repeat="hour in choices" value="{{hour.id}}">{{hour.name}}</option>
</select>
其他地方(在HTML页面中)......
{{totalHours}}
我想要做的是每次更新这个选择字段时,我想运行一个更新和重新计算代码中前面显示的另一个值的函数。这就是这个功能:
$scope.UpdateTime = function() {
totalHours = currentTimeStartHour - 3;
return totalHours;
};
我目前得到的结果是该函数根本不运行。我是棱角分明的新人,现在已经挣扎了一段时间。有人可以帮助我或指出我正确的方向吗?
<select ng-model="currentTimeStartHour"
ng-change="UpdateTime()">
<option ng-repeat="hour in choices" value="{{hour.id}}">{{hour.name}}</option>
</select>
{{totalHours}}
在控制器中
$scope.UpdateTime = function() {
$scope.totalHours = $scope.currentTimeStartHour - 3;
};
$scope.UpdateTime = function(currentTimeStartHour) {
$scope.totalHours = currentTimeStartHour - 3;
};
在您的HTML中:
<select ng-model="currentTimeStartHour" style="width: 33%" ng-change="UpdateTime(currentTimeStartHour)">
<option ng-repeat="hour in choices" value="{{hour.id}}">{{hour.name}}</option>
</select>