Michael Woldemedihin Michael Woldemedihin - 3 months ago 16
AngularJS Question

I am getting Error: [ng:areq] Argument 'employeeObj' is not a function, got undefined, and i couldnt figure out what i missed

I am getting Error: [ng:areq] Argument 'employeeObj' is not a function, got undefined, and i couldnt figure out what i missed. Can any body help me?


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<script src="Scripts/angular.js"></script>
<script>
"use strict"

function Employee($scope, $rootScope) {
debugger;
$rootScope.counter = (($rootScope.counter||0)+1);
$scope.FirstName = "demo";
$scope.LastName = "demo";
$scope.Validate = function () {
if ($scope.FirstName == 0 || $scope.LastName == 0) {
alert("No!")
} else {
alert("Yes!")
}
}
}
var empApp = angular.module("employeeApp", []);
empApp.controller = ("employeeObj", Employee);
</script>
<body>
<div ng-app="employeeApp">
<div id="empScreen" ng-controller="employeeObj">
First Name: <input ng-model="FirstName" id="FirstName" type="text" value=" " /><br />
Last Name: <input ng-model="LastName" id="LastName" type="text" value=" " /><br />
{{FirstName}}<br />
{{LastName}}<br />
{{counter}}<br />
<input type="button" value="Validate" ng-click="Validate()" />
</div>
</div>
</body>
</html>

Answer

Try this change in controller implementation on the angular part instead:

var empApp = angular.module("employeeApp", []);
empApp.controller('employeeObj', Employee); // <-- change here

Before

empApp.controller = ('employeeObj', Employee); <-- remove the equal sign