【发布时间】:2017-11-12 12:41:35
【问题描述】:
我正在尝试在我的视图中创建延迟操作。
单击按钮时,会出现相应的消息,但是我希望该消息在 2000 毫秒内消失。
我发现了一些推荐 $timeout 的情况,并且我似乎遵循了这些情况下的解决方案,但是 $timeout 函数不会更改标签文本。
为什么我的$timeout 在这种情况下不起作用?
感谢您就此事提供任何指导。请在下面找到我的代码。
// app.js
var app = angular.module('myApp', []);
// mainController.js
app.controller("mainController", ["$scope", function($scope, $timeout) {
$scope.fireTrigger = function(str) {
$scope.triggeredValue = (str) + " fired";
$timeout(function() {
$scope.triggeredValue = "";
}, 2000);
}
}]);
// index.html
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<title>myApp</title>
<link rel="stylesheet"
href="entertainment.css">
</head>
<body ng-controller="mainController">
<h3 ng-bind="triggeredValue"></h3>
// ...
【问题讨论】:
标签: javascript angularjs timeout