我试图弄清楚为什么我的超时功能会出错,从而限制了模型值的变化。
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初始化不悬挂。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句