Apologies if my question seems basic, but I am currently learning about AngularJS controllers.
Below is the structure of my project:
https://i.sstatic.net/EQOel.png
Here is the snippet of my HTML code:
<!doctype html>
<html ng-app>
<head>
<script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.min.js"></script>
<script src="js/controllers.js" />
</head>
<body>
<div ng-controller="numberController">
<input type = "text" ng-model = "number.number1" placeholder = "Enter a number here">
<input type = "text" ng-model = "number.number2" placeholder = "Enter another number here">
{{number.number1}} + {{number.number2}} = {{number.sumIt()}}
</div>
</body>
</html>
This snippet shows my controller implementation:
function numberController($scope) {
$scope.number = {
number1: 0,
number2: 0,
sumIt: function() {
var numObj;
numObj = $scope.number;
return parseInt(numObj.number1) + parseInt(numObj.number2);
}
};
}
I'm facing issues with loading the webpage and seeking guidance on what could be wrong.
Upon further investigation, I received this error message: Error Message Link.
I made some updates to my controller as follows:
var saApp = angular.module("saApp", []);
saApp.controller('numberController', function($scope) {
$scope.number = {
number1: 0,
number2: 0,
sumIt: function() {
var numObj;
numObj = $scope.number;
return parseInt(numObj.number1) + parseInt(numObj.number2);
}
};
});
Additionally, here is an updated version of my HTML code:
<!doctype html>
<html>
<head>
<script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.min.js"></script>
<script src="js/controllers.js" />
</head>
<body>
<div ng-app = "saApp" ng-controller="numberController">
<input type = "text" ng-model = "number.number1" placeholder = "Enter a number here">
<input type = "text" ng-model = "number.number2" placeholder = "Enter another number here">
{{number.number1}} + {{number.number2}} = {{number.sumIt()}}
</div>
</body>
</html>