Angular JS TypeError:f不是函数

Aja*_*jay 15 javascript angularjs

我试图找出为什么我的超时功能给出错误,从而限制模型值的变化.

angularExample.html

<!DOCTYPE html>
<html ng-app="Tutorial">
  <head>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
    <script type="text/javascript" src="scripts/app.js"></script>
  </head>
<body ng-controller="MyController">  
     <input type="text" ng-model="data" />
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

app.js

(function() {

  var app = angular.module('Tutorial', []);
app.controller("MyController",function($scope,$timeout){

    $scope.data="hi";
    $timeout(callAtTimeout,3000);

    var callAtTimeout=function(){$scope.data="hello";}
});
})();
Run Code Online (Sandbox Code Playgroud)

错误快照: 在此输入图像描述

Zee*_*Zee 14

您需要先定义callAtTimeout然后再使用它.

var callAtTimeout=function(){console.log("hi")}
$timeout(callAtTimeout,3000);
Run Code Online (Sandbox Code Playgroud)

Javascript中的初始化不会被挂起.