Javascript AngluarJS$超时不工作

Javascript AngluarJS$超时不工作,javascript,angularjs,timeout,Javascript,Angularjs,Timeout,我试图在我的视图中创建一个延迟操作。 单击按钮时,会显示相应的消息,但我希望消息在2000毫秒内消失。 我发现有些情况下建议使用$timeout,我似乎遵循了这些情况下的解决方案,但是$timeout函数不会更改标签文本 在这种情况下,为什么my$timeout不起作用 我感谢你对此事的指导。请在下面找到我的代码 //app.js var app = angular.module('myApp', []); //mainController.js app.controller("mainCon

我试图在我的视图中创建一个延迟操作。
单击按钮时,会显示相应的消息,但我希望消息在2000毫秒内消失。
我发现有些情况下建议使用
$timeout
,我似乎遵循了这些情况下的解决方案,但是
$timeout
函数不会更改标签文本

在这种情况下,为什么my
$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>
// ...

myApp
// ...

在控制器的工厂函数中使用依赖项之前,在内联数组中注入依赖项

app.controller("mainController", ["$scope", "$timeout", //<-- add $timeout dependency
   function($scope, $timeout) {

app.controller(“mainController”、[“$scope”、“$timeout”、//谢谢你说得对,我还注意到我忘了在onclick函数中调用函数本身。