Unexpected token error encountered in AngularJS

Hey Team,

I encountered an error while trying to add an employee. I'm looking for a way to dynamically add employees and display them on the list screen.

Additionally, how can I access the employees from a different JS file?

A SyntaxError occurred at memory-services.js:8 - Unexpected token var. Also, there's an AngularJS error at angular.js:6. Click here for more details.

(function () {

    var employees = [],
        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);

    function addEmployee(emp) {
        employees.push(emp);
    }

    function findById(id) {
        var employee = null,
            l = employees.length,
            i;

        for (i = 0; i < l; i++) {
            if (employees[i].member_id === id) {
                employee = employees[i];
                break;
            }
        }

        return employee;
    }

    function findByManager(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));
                    }
            }
        ]);

}());

Answer №1

Below are the definitions of your variables:

var employees = [];

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

Please note that you should place var before the variable declaration or use a semicolon instead of a comma to prevent syntax errors.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Most efficient method for implementing a recursive function while looping through elements in an array

Let's consider a scenario where we have an array of letters: const letters = ['a','b','c','d']; In addition, we have a function that requires a string argument letter and generates a concatenated output of that ...

Is it possible to dynamically display content based on click events in React JS?

Is there a way to dynamically render content based on conditions, but instead of directly calling {renderAuthButton()} in the return statement, I would like to trigger it with an onClick event? class App extends Component { // ... render() { let ...

Rise to the occasion when you hover

I'm in search of a function similar to the one found at . When you hover over the tablet, it appears. I want the same feature but with slightly different elements. My plan is to display 3 mobile devices at the top of my website, partially hidden, but ...

AngularJS experiencing initialization issues when attempting to use Spectrum.js

I have integrated angular-spectrum-colorpicker to incorporate spectrum.js into my code. Although it functions well overall, I am encountering an issue where the value is not initialized with the model. Below are the settings that I have implemented: <s ...

How are jQuery.ajax and XMLHttpRequest different from each other?

My goal is to fetch and run the script contained in a file named "example.js" using an AJAX request. Suppose the content of example.js looks like this: const greetings = { hello: "Hello", goodBye: "Good bye" } console.log(greetings.hello) In anot ...

Having trouble with the page loading properly

Here is the code snippet I am working with: <div id="logo" style="text-align:center;"> <p>AXIS'14</p> <a id="enter" onclick="EnterSite()">Enter Website</a><br> </div> <div id="content"> //i ...

ReactJS Antd displays a faulty design on the webpage

Currently, I am utilizing Antd for a ReactJs project, however, I have noticed an issue with the rendering of components in the layout. Below is the code snippet: import React from 'react'; export default class Test extends React.Component { ...

The justify-between utility in Tailwind is malfunctioning

Can someone help me figure out how to add justify-between between the hello and the user image & name? They are in different divs, but I've tried multiple ways without success. I'm fairly new to this, so any advice would be appreciated. This ...

Displaying Kartik's growling animation using AJAX within Yii2 framework

Utilizing kartik growl to display a message via ajax success I attempted the following: This is the javascript code: $.post({ url: "forwardpr", // your controller action dataType: 'json', data: {keylist: keys,user:userdata}, success: f ...

Best practices for securely storing JWT tokens from an API in next-auth

I followed an online tutorial to implement this in next-auth import NextAuth from "next-auth" import Providers from "next-auth/providers"; const https = require('https'); export default NextAuth({ providers: [ Providers ...

Is it possible to set up the material-ui datepicker to allow for the selection of dates spanning across multiple months without losing visibility of the current month?

Is it possible to choose dates within the same calendar week, regardless of whether they fall in different calendar months? For instance, selecting Friday from the previous month when the new month begins on a Saturday. To illustrate my point, let's ...

Tips for showcasing embedded content in WordPress without the need for scrolling

I am in the process of building a website. The sidebar menu contains a list of pages and posts from my WordPress blog. Whenever I select a menu item, the content is displayed within one of the templates I have created in an Iframe. However, there seems to ...

Having trouble fetching the value with the designated ID

I'm encountering an issue with retrieving a value using an id. In my code, I have it set up like this: view <input type="text" value="<?php echo $add->class;?>" name="cls_<?php echo $add->id;?>" id="cls_<?php echo $add->id ...

Creating string enums in NextJS with TypeScript

I am working on my nextjs application and I have a component with a prop that is a string. I decided to create an enum, so I attempted the following: enum Label { dermatology = 'Dermatologi', psychology = 'Psykologi', rheumatology = ...

Is there a way to retrieve information from an external URL in JSON format and display it using JavaScript on a separate HTML webpage?

I'm trying to display the value TotalPostNotificationCount from a JSON file in an external HTML using either JavaScript or PHP. The JSON data is as follows: { "DayPostCount": 1, "TotalPostNotificationCount": 7381 } This data can be found at t ...

What is the correct process for authenticating requests from SSR to the Feathers JS API?

There are some examples available on how to access FeathersJS API from SSR, but the important aspect of authorizing such requests is missing. Is it feasible to create a feathers-client app for each request? Wouldn't that put too much load on the syste ...

Creating dynamic components in Vue.js using VueJS and jQuery synergistically

New to Vue.js and in the process of building a Vue component inspired by this custom select menu. I want to include an ionicon with each list item. Typically, I can add the icon in Vue.js using: <component class="icon" :is="name-of-icon& ...

What is the best way to incorporate images and videos into a JSON quiz format?

I am working on creating a quiz using JSON, jQuery, and JavaScript. Here is the question I have in JSON format: "questions": [ { "q": "At a birthday party you counted 120 eyes. How many people were at the party?", "a": [ ...

The magic of data binding in AngularJS's ng-repeat

Is it possible to dynamically call an attribute of a data-binded object based on the ng-repeat object? I have set up a simple example, but I'm not sure if it can be solved this way. Can anyone help with this? The goal is for the input to receive the ...

How to implement caching using XMLHttpRequest?

As someone who has primarily relied on jQuery's AjAX method, I am relatively new to using XMLHttpRequests. However, due to performance concerns in a web worker environment, I now find myself having to resort to the classic XMLHttpRequest. Currently, ...