小时和分钟到秒

时间:2015-12-02 10:47:18

标签: javascript angularjs html5

我想将小时和分钟转换为秒,这些将发送到API,但我没有转换秒。我应该向API发送什么价值。

HTML:

<form ng-submit="vm.handleAddBrief(vm.briefAttractionData)">
<div class="form-group">
        <label class="control-label col-md-3">Duration
        </label>
        <div class="col-md-6">
            <div class="input-group input-medium margin-top-10" name="duration">
                <input type="text" class="form-control" ng-model="vm.briefAttractionData.hours">
                <span class="input-group-addon">
                                                                   hrs
                                                                 </span>
                <input type="text" class="form-control" ng-model="vm.briefAttractionData.minutes">
                <span class="input-group-addon">
                                                                  mins
                                                                 </span>
                <!--{{seconds | secondsToDateTime | date:'HH:mm:ss'}}-->

            </div>
        </div>
      </form>

控制器:

function addBriefController($scope, $state, $timeout, $location, addBriefService) {

        var vm = this;

        vm.handleAddBrief = function (data) {
            var duration = function(data) {
               var hrs = Math.floor(data.hours * 3600);
               var min = Math.floor( data.minutes * 60);
               var totalSeconds = Math.floor(hrs + min);
            }


        addBriefService.addBrief(data, function (response) {    
            if (response.status === 200) {
                $state.go('newAttraction.image');
            } else {
                $state.go('newAttraction.image');
            }
        });
}

1 个答案:

答案 0 :(得分:1)

为什么你有#39;持续时间&#39; handleAddBrief代码里面的函数。在从UI提交表单时,handleAddBrief函数被调用,并且&#39;持续时间&#39;函数正在初始化但它没有被调用。要么明确地打电话给&#39;持续时间&#39;功能在“手柄”中的功能&#39;功能或删除它 我为解决方案创建了一个小提琴,你可以看看:http://jsfiddle.net/azwspw3x/1/
代码如下所示:

$scope.handleAddBrief = function (data) {
           var hrs = Math.floor(data.hours * 3600);
           var min = Math.floor( data.minutes * 60);
           var totalSeconds = Math.floor(hrs + min);
           $scope.ts = totalSeconds
        }
}