I am learning AngularJS. Now I am initializing variable using ng-init. But the variable value is always undefined. My code is below:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Angularjs popup</title>
<script src="http://localhost:8888/angular/angular-js.min.js"></script>
</head>
<body>
<section ng-app="myApp" ng-controller="MainCtrl" ng-init="quantity=1;cost=5">
</section>
</body>
<script type="text/javascript">
var myApp = angular.module('myApp', []);
myApp.controller('MainCtrl',function($scope){
alert($scope.quantity)
})
</script>
</html>
When I run above code, it is always alerting "undefined" for quantity even if I initialized using ng-init. What is wrong with my code? Can I not initialize like that?