Can't seem to find a solution to my Angular issue, despite searching for it extensively?
After starting to learn Angular recently, I've put together the following code based on various online resources.
Here's the HTML:
<div data-ng-app="appAuthentication">
<form name="authentication" method="post" data-ng-controller="AuthenticationController" data-ng-submit="doAuthentication(authentication)" novalidate>
<fieldset>
<label for="sign-in-email-address">Email address:</label>
<input id="sign-in-email-address" name="sign-in-email-address" data-ng-model="authentication.emailAddress" type="text" required />
<label for="sign-in-password">Password:</label>
<input id="sign-in-password" name="sign-in-password" data-ng-model="authentication.password" type="password" required />
<button type="submit">Go »</button>
</fieldset>
</form>
</div>
And here is my Angular script:
angular.module('appAuthentication', [])
.controller('AuthenticationController', ['$scope', function($scope, $http) {
$scope.authentication = {
emailAddress: '',
password: ''
};
$scope.doAuthentication = function(authentication) {
// console.log('Hello ' + authentication.emailAddress);
$http({
method : 'POST',
url : '/actions/authentication/sign-in.php',
data : authentication.emailAddress
})
.success(function () {
console.log('Success');
})
.error(function () {
console.log('Failure');
});
};
}]);
The error message in the console reads as follows:
TypeError: undefined is not a function
at k.$scope.doAuthentication (http://cms2.indypub.co.uk/static/scripts/core.js:16:4)
at http://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.min.js:176:88
at http://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.min.js:193:165
at k.$eval (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.min.js:111:373)
at k.$apply (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.min.js:112:121)
at HTMLFormElement.<anonymous> (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.min.js:193:147)
at http://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.min.js:31:161
at q (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.min.js:7:290)
at HTMLFormElement.c (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.min.js:31:143)
Once I uncomment the initial console.log statement in the JavaScript file, the emailAddress is displayed in the console log.
If you have any insights into where I might be making a mistake, I would greatly appreciate your feedback.
Thank you,
Tony.