【发布时间】:2018-02-09 10:52:51
【问题描述】:
我正在构建员工工作跟踪应用程序,我在 UI 中有一个开始和停止按钮。
我的玉码:
td.table-icon-cell
a.btn.btn-primary(type='button' href='',ng-click='stop();' ng-if="start.active")
i.fa.fa-stop(aria-hidden='true') Stop
a.btn.btn-primary(type='button' href='',ng-click='start();' ng-if="!start.active")
i.fa.fa-clock-o(aria-hidden='true') Start
controllers.js:
$scope.start = function () {
$scope.time = {
start : moment(new Date()),
stop : ''
}
$scope.start.active = true;
$http.post('/api/timestart', $scope.time).then(function (response) {
$scope.savetimes = response.data;
});
}
$scope.stop = function () {
$scope.start.active = false;
$scope.time = {
start: '',
stop: moment(new Date())
}
$http.post('/api/timestop', $scope.time).then(function (response) {});
}
例如:
我是一名员工,我按下“开始”按钮,然后它变成“停止”按钮,它很好,但如果我加载我的页面,我想要再次“停止”按钮,但它首先显示“开始”。
【问题讨论】:
-
$scope.start.active的默认值是多少? (你在你的控制器中初始化它吗?) -
是的,看看我的代码:我有两种模式,$scope.start.active = true 和 false。
-
它们仅在您调用以下任一函数时设置:start()、stop()。当您加载您的页面时,是否会触发任何功能?否则
$scope.start.active将是未定义的 -
是的,怎么写东西?如果用户一旦点击开始,我想在 UI 中显示停止按钮,即使页面加载仍然用户需要再次按下停止。
-
在你的控制器中,尝试在任何函数之外初始化
$scope.start.active = false;
标签: javascript angularjs date time