javascript - Angular JS 类型错误 : f is not a function

标签 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>

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";}
});
})();

错误快照: enter image description here

最佳答案

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

var callAtTimeout=function(){console.log("hi")}
$timeout(callAtTimeout,3000);

Javascript 中的初始化不是 hoisted

关于javascript - Angular JS 类型错误 : f is not a function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30620895/

相关文章:

javascript - 404 未找到 Node

javascript - 如何将base64音频数据解码为wav格式

javascript - jQuery Mask 不允许递归输入

javascript - 专注于关闭模态框或弹出窗口

javascript - meteor 自动成型 : form with id "asdf" needs either "schema" or "collection" attribute

javascript - 如何在一个字符串中搜索第二个字符串中包含的所有单词?

javascript - 非 200 时 Angular 没有得到响应

AngularJS十进制输入: change comma to dot

javascript - AngularJS 指令添加其他不起作用的指令

json - angularjs - ng-重复 : access key and value from JSON array object