javascript - function got undefined. Basic program -
i new @ this. looked @ different examples still cannot figure wrong code
index.html
<html ng-app="main"> <head> <script src="angular.min.js"></script> <script src="app.js"></script> </head> <body ng-controller="maincontroller"> {{3 + 2}} </body> </html>
app.js
(function() { angular.module("main", []) .controller("maincontroller", maincontroller); var maincontroller = function($scope) { $scope.message = "hello angular!"; }; }());
'maincontroller' got undefined because called before declare.
solution: declare 'maincontroller' before call.
(function() { var maincontroller = function($scope) { $scope.message = "hello angular!"; }; angular.module("main", []) .controller("maincontroller", maincontroller); }());
Comments
Post a Comment