我试图弄清楚为什么我的超时函数会出错,从而限制模型值的更改。
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";}
});
})();
错误快照:
最佳答案
您需要先定义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/