Angular JS TypeError: f is not a function
You need to define callAtTimeout
first then use it.
var callAtTimeout=function(){console.log("hi")}
$timeout(callAtTimeout,3000);
Initializations in Javascript are not hoisted.
You are defining the callAtTimeout function after it its call. You need to have it above it.
Working fiddle
Sample code:
(function () {
var app = angular.module('Tutorial', []);
app.controller("MyController", function ($scope, $timeout) {
var callAtTimeout = function () {
$scope.data = "hello";
}
$scope.data = "hi";
$timeout(callAtTimeout, 3000);
}); })();
You just need to re-arrange the order of your code, the definition for callAtTimeout function should be before you use it. Working example:
(function() {
var app = angular.module('Tutorial', []);
app.controller("MyController",function($scope,$timeout){
var callAtTimeout=function(){$scope.data="hello";}
$scope.data="hi";
$timeout(callAtTimeout,3000);
});
})();
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="Tutorial" ng-controller="MyController">
<input type="text" ng-model="data" />
</body>