Seeking assistance in generating random first and last names based on gender for a form using Angular. I am relatively new to Angular and keep encountering this error whenever the
Use of undefined constant firstName - assumed 'firstName'
Here's my View:
@section('content')
<form ng-app="getNameApp" ng-controller="getNameController">
Male<input type="radio" ng-model="gender" value="male" name="gender" /><br />
Female<input type="radio" ng-model="gender" value="female" name="gender" /><br />
<input type="text" ng-model="{{ firstName }}" name="firstName" />
<input type="text" ng-if="{{ lastName }}" value="{{ lastName.body }}" name="lastName" />
<button ng-click="randomNameController()">Randomize</button>
</form>
@stop
This is my JS file
angular.module('getNameApp', [])
.controller('getNameController', getNameController);
function getNameController ($scope, $http) {
$scope.gender = 'male';
var randomName = $http({
url: '/randomName',
method: "GET",
params: {gender: $scope.gender}
});
randomName.success(function(data) {
$scope.firstName = data.firstName;
$scope.lastName = data.lastName;
});
randomName.error(function() {
document.write(randomName);
});
}
This is my Controller
public function randomName () {
$faker = Faker\Factory::create();
$gender = Input::get('gender');
if ($gender == 'male') {
$names = [
'firstName' => $faker->firstNameMale
];
} else {
$names = [
'firstName' => $faker->firstNameFemale
];
}
$names['lastName'] = $faker->lastName;
return $names;
}
Update: Upon checking the network tab in inspect element, it indicates a 500 internal server error with createCharacter route (page).