Angular service does not function as expected

In my Angular project, I have implemented a basic logging service:

app.service('$userInteraction', [function() {

  var userLog = "";

  this.log = function (datetime, screen, logMessage) {
    userLog.concat(datetime + "\t" + screen + " Screen\t" + logMessage + "\n");
  }

  this.getLog = function () {
    return userLog;
  }

  this.clearLog = function () {
    userLog = "";
  }

}]);

Within one of my controllers, I make use of this logging service like this:

app.controller('myController', ['$scope', '$userInteraction', function($scope, $userInteraction) {

    $userInteraction.log(Date(), 'Login', 'Some random message.');

}]);

However, upon running the code, I encounter the following error:

TypeError: $userInteraction.log is not a function

I could have sworn that it was working correctly before. Being new to Angular, this might be due to a rookie mistake on my part. Any help would be greatly appreciated!

Answer №1

Although this inquiry may be dated, it could still assist others in need. If you encounter issues while running your code on Plunker, there may be duplicate service names causing the problem. Take a thorough look through all AngularJS files to ensure there are no services with identical names.

I faced a similar issue before where two services shared the same name, resulting in the function not being called as expected.

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

I prefer my information to be arranged neatly and separated by spaces

Is there a way to display data neatly formatted with space between each entry? I'm not sure why id one is not being selected I prefer using the append method so I can dynamically add content later on How can I organize data into two columns, wit ...

Tips on how to postpone the execution of my ng-init function until my API call is completed successfully

Currently, I am working on a dynamic form that utilizes ng-repeat. To load the location data, I am using oi-select within a modal popup. On click of the modal open button, an API function is triggered to fetch the location values. However, I encountered an ...

Express JS res.send() with an array response data is posing a concern during the Checkmarx scan

When using the axios library in my express middleware to retrieve responses from APIs, I encountered a security concern raised by Checkmarx scan report. router.post(someurl,req,res) { axios .get(someurl) .then((response=>{ **res.send(response.data);**/ ...

What is the procedure for initiating a POST request when the payload is ready for submission?

After a successful payment, my success page is displayed with a URL that includes a query parameter. I want to make a POST request to my API endpoint when the page loads, but I'm encountering an issue where the first POST request is empty (router.quer ...

Select/Deselect all, no modification to the arrangement HTML/JavaScript

Currently in the process of building a simple website, I've hit a snag. I have various checkboxes that allow users to toggle certain elements on and off (primarily for layout purposes) and I've implemented a check/uncheck all button. The issue ...

Can anyone recommend any quality libraries for uploading files in Silverlight or HTML that also support metadata?

I am in the process of developing a solution within SharePoint 2010 that allows for the upload of multiple documents while also tagging them with metadata. Is there anyone familiar with an innovative file-upload control or solution that enables the additi ...

AngularJS deferred rendering (not deferred loading views)

Imagine having over 3000 items to display within a fixed-height div using an ng-repeat and setting overflow: auto. This would result in only a portion of the items being visible with the rest accessible via scrollbar. It's anticipated that simply run ...

Should we consider using a boolean-returning function for ng-show?

Will continuously watching a function's value or using it in a directive like ng-show have a performance impact due to the function being called each cycle? Could it be more efficient to simply use a boolean value to determine this, and update that v ...

Error: jQuery JSONP syntax error due to missing semicolon before statement

Currently, I have implemented the following code to access a rest service that is hosted on a different domain: $.ajax({ type: 'GET', url: url, async: false, jsonpCallback: 'jsonCallback' ...

Switch between classes based on the query using the Ajax response

In order to retrieve data from a database and determine if the field "is_recurring" is set to 1 or 0, I am utilizing an ajax call to my functions.php file. This value is based on a selection made in a dropdown menu. Depending on the result returned by the ...

How to format numbers with commas in AngularJS to make them easier to read

One of my variables looks like this: $scope.numbers = 1234567. When I apply the filter {{numbers| number : 0}}, the result is 1,234,567. Is it possible to get a result like 12,34,567 instead? Thank you in advance. ...

Calculating a cumulative total in AngularJS ng-repeat using the value

In need of a solution while working with angularjs to maintain a running total based on data values. The current code always calculates the total value for all items combined. <div ng-repeat="child in pItem.childItems | orderBy:'displayOrder' ...

Interacting with the DOM of an iFrame from a separate window using Javascript

My main webpage is hosted on "DomainA" and it contains an iFrame sourced from "DomainB". Within this iFrame, there is a click event that opens a new window, also sourced from "DomainB". I am attempting to update an input field within the iFrame from the n ...

Having issues with validating a form using Yup for a Checkbox input?

My form is built using mui, formik, and yup. If the input fields are empty (e.g. "surname") after clicking the submit button, an error is displayed. However, the issue arises when the checkbox for Terms of Service isn't checked as no error shows up. ...

AngularJS Incorrectly marked checkbox

I am encountering an issue with a template using AngularJS. The template displays a list of books with checkboxes for performing batch actions such as deleting the books. If the list gets too long, the books are paginated. The problem arises when I check ...

Is it possible to transform a Vuejs project into Vue-Native?

I recently completed a Vue.js project and now I'm interested in turning it into a native app. I'm wondering if I'll need to completely rewrite the application using Vue-Native components, or if there is a way to convert my existing project i ...

Node.js is being utilized to send an abundance of requests to the server

Here is my setup: var tempServer=require("./myHttp"); tempServer.startServer(8008,{'/fun1':fun1 , '/fun2': fun2 , '/fun3':fun3 , '/fun4':fun4},"www"); This code creates a server on localhost:8008. If I enter th ...

In search of grabbing an image from a list item and relocating it to sit before the division tagged with class "event-title"

I am struggling with selecting each list element within the ul and moving the image inside the div class="event-details" above the div with the class="event-title". This adjustment is necessary for achieving the desired styling since the wordpress Event pl ...

I encountered a validation error and a 404 error while trying to input data into all fields. Kindly review and check for accuracy. Additionally, I have included an

click here for image description Despite providing all details in the form fields, I keep receiving an error message prompting me to enter all fields... I am also encountering a "/api/user 404 Not Found" error and unsure of the reason. Interestingly, wh ...

Issue with passing hidden data to PHP script using AJAX

I've been trying to troubleshoot my ajax/json script without success. I've searched on stackoverflow for solutions but nothing seems to be helping. My goal is simple - when a user clicks on a submit button, I want to send a hidden input value to ...