gpt4 book ai didi

javascript - 无法使用 Angular js 中的选项卡从日期选择器中获取选定的日期

转载 作者:行者123 更新时间:2023-11-28 07:06:11 26 4
gpt4 key购买 nike

我在 Angular Bootstrap 的选项卡集元素中使用日期选择器。当我在选项卡内使用日期选择器并选择日期时,我无法在 Controller 中获取所选日期的正确值。

如果我删除该选项卡,那么我可以获得当前选择的日期。代码在 plunker 中: http://plnkr.co/edit/dIJRDQUYdrKmChdIt9T2?p=preview

 <form name="form" class="form-horizontal" ng-controller="ctrl">
<tabset>
<tab justified="true">
<tab-heading>
Main
</tab-heading>
<div class="form-group">
<label class="col-xs-2 control-label" for="etaDate">ETA Date</label>
<div class="input-group col-xs-6 col-sm-4 col-md-2">
<input class="form-control" id="etaDate" name="etaDate" type="text" ng-model="eta" datepicker-popup="dd/MM/yyyy" is-open="opened.open" show-weeks="false" />
<span class="input-group-btn">
<button class="btn btn-default" ng-click="open($event)"><i class="glyphicon glyphicon-calendar"></i></button>
</span>
</div>
</div>
<button ng-click="getdate()">GET DATE</button>
</tab>
</tabset>
</form>

script.js

angular.module('myApp', ['ui.bootstrap']);
var ctrl = function($scope) {
$scope.opened = {};

$scope.open = function($event) {
$event.preventDefault();
$event.stopPropagation();
$scope.opened.open = true;
};
$scope.eta = new Date();

$scope.getdate = function (){
alert($scope.eta)
};

};

最佳答案

可以通过两个选项卡找到下面的工作演示: http://embed.plnkr.co/RkLGqy5zZjfCqlCuuNPF/preview

“Tabset”目录在主范围内使用自己的属性创建自己的隔离范围,并且不会将属性继承到父级。为了解决这个问题,正如 @charlietfl 所说,我们应该在 ng-model 中使用点 (.)。

为了更好地理解,请查看https://github.com/angular-ui/bootstrap/issues/1553#issuecomment-31980027

更简要的解释:https://stackoverflow.com/a/14049482/1252454

关于javascript - 无法使用 Angular js 中的选项卡从日期选择器中获取选定的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31698114/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com