angular JS意外令牌

时间:2014-12-22 20:38:54

标签: javascript angularjs

当我尝试添加员工时,我收到以下错误。我希望能够灵活地动态添加员工并填充列表屏幕。

另外,请告诉我,如何从不同的JS文件访问员工?

  

memory-services.js:8 Uncaught SyntaxError:意外的令牌变量   2014-12-22 14:33:02.365angular.js:6未捕捉错误:   [$喷油器:modulerr]   http://errors.angularjs.org/undefined/ $注射器/ modulerr P0 = MyApp来&安培; P1 =错误%...%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:"kingskuri@hotmail.com",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));
                   }
               }

           }]);

}());

1 个答案:

答案 0 :(得分:1)

这是你的变量定义:

var employees = [],

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

请注意您如何将var放在,运算符之后。这会导致语法错误。

您要么删除var,要么添加;而不是逗号,这样可以解决问题。