Employing an assortment of data points within a manufacturing facility

Currently, I have a factory that utilizes a JSON file wrapped in a $http.get request for testing purposes. However, this approach is not suitable when working within a SharePoint environment where JSON files are restricted. In the end, the goal is to integrate this with a web API call.

How can I define the JSON values within the factory to facilitate testing?

(function() {
var customDataFactory = function($http) {

    var factory = {};

    factory.getCustomData = function() {
        return $http.get('testdata.json');
    };



    return factory;
};

customDataFactory.$inject = ['$http'];

angular.module('app').factory('dataFactory', 
                                       customDataFactory);

}());

Example of JSON data:

[
{
"Segment": "Trading",
"Title": "John Doe",
"Role": "Manager",
"Last Meeting Date": "1/1/2022",
"nextmeetingowner": "",
"CreatedDate": "1/1/2022",
"Modified": "1/1/2022",
"primaryaccountability": "Jane Smith",
"otherltEngaged": "Alice Johnson, Bob Brown",
"upcomingdate": ""
},
{
"Segment": "Finance",
"Title": "Jane Smith",
"Role": "Financial Analyst",
"Last Meeting Date": "12/31/2021",
"nextmeetingowner": "",
"CreatedDate": "1/1/2022",
"Modified": "1/1/2022",
"primaryaccountability": "John Doe",
"otherltEngaged": "Bob Brown, Cindy Davis",
"upcomingdate": ""
},]

Answer №1

To effectively utilize JSON in your factory, assign it to a variable and encapsulate it within your functions.

http://plnkr.co/edit/gWklBTEZWqxPzQjhV19D?p=preview

<!DOCTYPE html>
<html>

  <head>
    <script data-require="angular.js@*" data-semver="1.3.0" src="//code.angularjs.org/1.3.0/angular.js"></script>
    <link rel="stylesheet" href="style.css" />
    <script src="script.js"></script>
  </head>

  <body ng-controller="myCtrl">

    {{myData}}

    <script>
      var app=angular.module("app",[]);

      app.factory("data",function($http){
        var data = [{name:'Bob'},{name:'Amy'}];
        return{
          getData : function(){
            return data;
          }
        }
      });

      app.controller("myCtrl",function($scope,data){

        $scope.myData = data.getData();

      });

      angular.bootstrap(document,["app"]);

    </script>
  </body>

</html>

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

Encountering issues with configuring an Express server with HTTPS

Having difficulty setting up my Express server on HTTPS and accessing my API. Below is the code I am using: // server.js const express = require('express'); const { readFileSync } = require('fs'); const https = require('https' ...

Analyze a designated section and display the top 3 frequently used words

Below is the code snippet provided: <body> <div id="headbox"> <p>Whatever...</p> </div> <div id="feed"> <div> <p>I hate cats</p> </div> <div> <p>I like ...

RSS feed showing null xml data with jQuery

Working on coding a straightforward RSS feed utilizing jquery and pulling data from Wired. Everything appears to be functioning correctly, except for one issue - after the description, an unknown value of NaN is appearing in the result. It seems to be comi ...

"Implementing a column template in jqgrid post-creation: A step-by-step

Can't apply column template with Free jqgrid once it's been created. I've attempted: var newOrderPriceTemplate = { align: "center", formatter: "showlink", formatoptions: { onClick: function() { alert('clicked&apos ...

The animation for the accordion feature in the iOS Framework7-vue app seems to be moving at

I am encountering issues with the iOS app while developing both android and iOS apps with Framework7-vue. The Android app functions smoothly, but the iOS app is causing trouble. One of the features include a popup functionality with an accordion inside fo ...

Tips on how to use console.log in react-simple-chatbot

I am currently working on a chatbot project and would like to add some features such as sending emails and popups. However, I am facing an issue with console logging elements in my code. Here is the snippet of my code: import React from "react"; ...

"Customizing FusionCharts: A step-by-step guide to changing the background color

Is there a way to modify the background color of fusionchart from white to black? Additionally, how can I change the font color in the chart? https://i.sstatic.net/MMuIq.png ...

Sliding divider across two div containers with full width

Seeking a JavaScript/jQuery function for a full page slider functionality. The HTML structure I'm working with is as follows: My objectives are twofold: Both slide1 and slide2 should occupy the full width of the page. Additionally, I am looking for ...

Issue with Angular Bootstrap DatePicker Directive (Eternicode version) failing to remain in open state

Recently, I've been working on incorporating the Bootstrap Datepicker by Eternicode into my application. To help with this integration, I stumbled upon a directive that utilizes it from this GitHub repository. Migrating the datepicker functionality to ...

Experience the classic game of rock-paper-scissors brought to life through JavaScript and HTML,

I've been working on a rock, paper, scissors game in JavaScript and I'm struggling to get the wins and losses to register correctly. The game keeps resulting in a draw even though I've checked my code multiple times. It's frustrating be ...

Exploring the connections between PHP, JavaScript, JSON, and AJAX

While this question may lean more towards conceptual understanding rather than pure programming, it is essential for me to grasp how these mechanisms interact in order to code effectively. My current knowledge includes: 1) PHP as a programming language ...

Opting for PHP over JSON in a jQuery live search code

Is it possible to modify my jQuery Google Instant style search script to pull content from a PHP script instead of using the BingAPI? Below is the current code being used: $(document).ready(function(){ $("#search").keyup(function(){ var searc ...

Retrieve the text content of the initial li element within each ul

I have numerous <ul> lists and I'm attempting to extract the text from the first li element of each list. The HTML markup is straightforward: <ul> <li>abc</li> <li>def</li> <li>ghi</li> </u ...

Styling Input elements with a unified border in Bootstrap

[Issue Resolved] I have been working on setting a single border between multiple inputs inside a form-group in Bootstrap. Currently, the border is only visible when the input is not focused and it is the last one. However, my expectation is for the bo ...

Is it possible to programmatically hide the Textarea and submit button for each row in a PHP-generated database table?

After spending a considerable amount of time on this project, I'm looking to incorporate a JavaScript effect (hide/unhide) into a basic submit form. Although the functionality is successful, it seems to be limited to only one row in the database tabl ...

Tips for including multiple directives in a component

Apologies in advance for my lack of clarity in expressing this question, which is why I am seeking assistance rather than finding the solution on my own. My query pertains to loading a component within another one and specifying it in the directive. Below ...

Expanding Java Classes and Replacing Methods with Multiple Parameters in ES4X/Graal

I am currently facing a challenge in my JavaScript project using ES4X/Graal, where I need to extend a Java class. This Java class has methods with overloaded parameters that I must override. While I understand how to call a specific Java method by specifyi ...

Calculate the difference and sum of time values with varying signs in JavaScript

-12:00 - 5:30 => -6:30 -2:00 - 5:30 => 3:30 00:00 - 5:30 => -5:30 6:00 - 2:30 => 3:30 I am interested in subtracting time with both positive and negative indices. let myCountries = [ { countryName: "NewZealand", ...

What is the best way to refresh my useEffect hook when a State change occurs in another component's file in ReactJS?

Seeking to execute an API call within useEffect() and aiming for the useEffect() function to trigger every time new data is appended to the backend. To achieve this, a custom button (AddUserButton.js) has been created to facilitate adding a new user to the ...

Tips for managing several Material UI Slide Components at once

Utilizing Material UI's Slide component, I have encountered an issue with my code. Upon hovering over a card, I intend for an individual slide to appear. However, the current implementation causes both slides to be displayed when hovering over any of ...