Ajay Ajay - 1 year ago 497
AngularJS Question

Angular JS TypeError: f is not a function

I'm trying to figure out as to why my timeout function is giving error, thereby restricting the change in model value.


<!DOCTYPE html>
<html ng-app="Tutorial">
<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>
<body ng-controller="MyController">
<input type="text" ng-model="data" />


(function() {

var app = angular.module('Tutorial', []);


var callAtTimeout=function(){$scope.data="hello";}

Error Snapshot:
enter image description here

Zee Zee
Answer Source

You need to define callAtTimeout first then use it.

var callAtTimeout=function(){console.log("hi")}

Initializations in Javascript are not hoisted.