0
私は自分のビューで遅延アクションを作成しようとしています。
ボタンをクリックすると、対応するメッセージが表示されますが、メッセージは2000msで消えます。
$timeout
が推奨されたいくつかのケースがありましたが、これらのケースでは一見解決策をたどりましたが、ラベルテキストは$timeout
機能によって変更されていません。
私の$timeout
がこの場合に機能しないのはなぜですか?
私はこの問題に関する指導を感謝します。以下の私のコードを見つけてください。
//
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>
// ...
私はonclick関数の中で、関数自体を呼び出すことを忘れていたことに気付きました。 –