Ramesh Sangili
Ramesh Sangili

Reputation: 1633

angular JS unexpected token

Team,

I am getting the following error when I try to addEmployee.. I want to have the flexibility to add employee dynamically and populate the list screen.

Also, please let me know, how do I access the employees from different JS file?

memory-services.js:8 Uncaught SyntaxError: Unexpected token var 2014-12-22 14:33:02.365angular.js:6 Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/undefined/$injector/modulerr?p0=myApp&p1=Error%…%20(http%3A%2F%2Flocalhost%3A8080%2Fdirectory%2Flib%2Fangular.js%3A28%3A48)

(function () {



    var employees = [],

    var addEmployeeDetail = {club_id:"27060",member_id:10118,member_name:"Rtn. Kuriachan K. A.",clasification:"Furniture Manufacturing",mobile_no:"9843677777",email_id:"[email protected]",img_url:""};
    addEmployee(addEmployeeDetail);
    addEmployee = function(emp) {
        employees.push(emp);
    },

    findById = function (id) {
           var employee = null,
               l = employees.length,
               i;
           for (i = 0; i < l; i = i + 1) {
               if (employees[i].member_id === id) {
                   employee = employees[i];
                   break;
               }
           }
           return employee;
       },

       findByManager = function (managerId) {
           var results = employees.filter(function (element) {
               return managerId === element.managerId;
           });
           return results;
       };


   angular.module('myApp.memoryServices', [])
       .factory('Employee', [
           function () {
               return {
                   query: function () {
                       return employees;
                   },
                   get: function (employee) {
                       return findById(parseInt(employee.employeeId));
                   }
               }

           }]);

}());

Upvotes: 0

Views: 1246

Answers (1)

dfsq
dfsq

Reputation: 193261

This is your variable definitions:

var employees = [],

var addEmployeeDetail = {
    club_id: "27060",
    member_id: 10118
    /* ... */
};

Note how you put var after the , operator. This makes syntax error.

You either remove var or put ; instead of comma, and it should fix the problem.

Upvotes: 1

Related Questions