"Upon receiving a successful response in AngularJS, the $scope variable triggers another

Is there a way to retrieve the $scope variable from an AngularJS success response in one function and use it in another?

$scope.mydoc = function() {
  var params = {
    tribe_id: $scope.parentCtrl.id
  };
  dealRoomApiService.getOfflineLoanDocs(params)
    .then(function(resp) {
      $scope.docList = resp.data;
    }, function(error) {
      toastr.error(error.data.detail); //Display a toast notification
    });
}

In the above code, how can I access the $scope.docList variable in the following function?

$scope.myDoc = function(doc, index) {
      console.log("Test....",$scope.docList);
    };

Answer №1

It seems like

dealRoomApiService.getOfflineLoanDocs
is a function that runs asynchronously. This code snippet should get the job done.

dealRoomApiService.getOfflineLoanDocs(params)
.then(function(response) {
  $scope.docList = response.data;
  $scope.myDoc();
}, function(err) {
  toastr.error(err.data.detail); //Display an error toast notification
});

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

The XMLHttpRequest onload() function is failing to pass an instance of the XMLHttpRequest object

I am facing an issue with a function that sends a basic AJAX request to my server. The JavaScript code in the browser is as follows: function testRequest() { var xhr = new XMLHttpRequest(); xhr.onload = () => { console.log("RESPONSE R ...

Using JQuery to Customize Navigation Menu Targeting

On my website, I am trying to make an href button and a menu fade in as the page loads. However, I am struggling to find the correct code due to its placement within multiple tags, especially since I am new to JS and JQuery. I have provided a fiddle with a ...

Conditions for JQuery Ajax handlingIs there anything specific you would

I am looking to implement a try-catch scenario in Laravel where, if successful, a certain message will appear and if it fails, a different message will be displayed. However, when executed successfully, it seems to display the second message instead. $.a ...

Building ASP.NET Web Requests and Generating Pages

Although I have only dabbled in ASP.NET for simple tasks recently, I am eager to tackle a more challenging project. My goal is to utilize ASP.NET and Javascript to: Create a web page, such as Default.aspx, that calls a web service The web service (possi ...

When trying to link a Redis microservice with NestJS, the application becomes unresponsive

I am attempting to create a basic hybrid app following the guidance provided by Nest's documentation, but I have run into an issue where the app becomes unresponsive without any errors being thrown. main.ts import { NestFactory } from '@nestjs/c ...

What is the most effective way to recycle connections in node-resque?

Currently, I am utilizing the node-resque API according to its documentation. However, each time I enqueue a new client connection is established as confirmed by CLIENT LIST. Is there a reason why it cannot maintain all tasks over a single connection? // ...

Exploring the power of Angular 2 Directive scopes

When it comes to Angular2, Directives do not come with "scopes", unlike Components. However, in my specific case, I require a Directive to establish a scope. Take a look at my App component - it contains an HTML template, and the foo directive could potent ...

Is there any effort being made to utilize jQuery for the css @media screen and (max-width: 768px) function?

Is there a solution for handling the @media screen and (max-width: 768px) in CSS? I have created a responsive navigation bar, but when I change the display property of an element from none to block on mobile screens, it also appears on larger screens. Is ...

Looping through the list items and attaching click listeners to them

Take a look at the code snippet below: // Loop through every child element for(j = 0; j < len; j++) { var entry = sortedArray[j]; // Create a new <li> element to hold each entry var entryLI = document.createElemen ...

Display a variety of HTML pages using the md-tab component

I'm currently learning about angular material and I have a question regarding how to display different HTML files for each md-tab. For instance, I want to set up 3 tabs: the first one should show catalog.html, the second should display manage.html, an ...

Trigger a jQuery event when a different selection is made in the dropdown menu

There are 2 choices available in the dropdown menu. <select id="_fid_140" onchange="chooseRecordPicker()" > <option value="736">9000000146</option> <option value="x3recpcker#">&lt; Browse choices... &gt;</option> Upo ...

Tips for programmatically inserting elements with data binding

Hi everyone, I'm relatively new to working with AngularJS and I have a question regarding dynamically adding elements to a page within a specific scope. For example, suppose we have the following HTML structure: <div id="cnt" ng-controller="main ...

Managing sessions with PHP and Angular.js involves retrieving and storing session data to maintain user

Seeking assistance on setting up a help session store using PHP and Angular.js for my login app. Upon successful login, the user's session should be stored and the session data retrieved upon redirection to the next page. Below is an outline of my cod ...

Linking this to a function that takes in arguments

I am currently working with an event handler that calls a fat arrow function to execute a specific method. import React, { Component } from 'react'; class App extends Component { sayHi = msg => { console.log(msg); }; render() { ...

Leveraging CSS or JavaScript for Displaying or Concealing Vacant Content Sections

I'm working on developing a page template that utilizes section headers and dynamically pulled content from a separate database. The current setup of the page resembles the following structure: <tr> <td> <h3> ...

Incorporate a widget with dynamic height adjustment

We are currently working on creating a widget that can be easily embedded by third-party websites. Our goal is to have the widget automatically adjust its height through the embed script. Initially, we considered using an IFrame generated by our JavaScrip ...

What is the best way to pass $scope variables to a controller?

I'm currently in the process of developing a system that involves listing items with specific attributes. Title Skills Budget Date Posted Additionally, I have implemented a modal that opens up when an item is clicked in the list. My goal is to retr ...

Enhance your programming experience by upgrading ESLint to support ECMA6 in the Br

Switching to ESLint in Brackets IDE After transitioning to coding JavaScript on Brackets IDE, I discovered the default linter was using an outdated version of JSLint. Wanting a more advanced tool, I installed ESLint as recommended by some documentation. ...

Bus Boy's employment record shows no termination

I am working on a Next Js project that includes an upload image endpoint. const busboy = require('busboy') export default function handle(req, res) { const bb = busboy({headers: req.headers}); bb.on('file', (fieldname, file, fi ...

What is the best way to serve my HTML and CSS files using my NODEJS server?

I have set up a nodejs server with the following code. Currently, I haven't included any references to HTML or CSS in the code because I am unsure how to do that. const http = require('http'); // Create an instance of the http server to ...