2017-11-12 6 views
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> 
// ... 

答えて

1

はそれを使用する前に、インライン配列に依存性を注入app.jsコントローラの工場機能

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

私はonclick関数の中で、関数自体を呼び出すことを忘れていたことに気付きました。 –

関連する問題