Errors with displaying prototype function in AngularJS ng-repeat as undefined

Encountering a problem where a function is returning 'undefined' in a select field.

<select name="supervisor"
    ng-model="editJudge.superID"
    ng-options="supervisor.legalProID as supervisor.fullName for supervisor in supervisors"
    class="form-control">

This is the function used to load supervisors.

function getLegalProfessionalsBroken() {
LegalProfessionalResource.query({isValid: true}).$promise.then(function(legalProfessionals) {
    $scope.supervisors = _.map(legalProfessionals, function(legalProfessional) {
        return new LegalProfessional(legalProfessional);
    });
});

}

Here's the definition of my LegalProfessional class.

function LegalProfessional(obj) {
var properties = $.extend({
    legalProID: null,
    firstName: null,
    lastName: null,
    middleName: null,
    email: null,
    isActive: true,
    insertedDate: null,
    insertedBy: null,
    modifiedDate: null,
    modifiedBy: null,
    deletedDate: null,
    deletedBy: null,
    typeID: null,
    superID: null
}, obj);

this.legalProID = properties.legalProID;
this.firstName = properties.firstName;
this.lastName = properties.lastName;
this.middleName = properties.middleName;
this.email = properties.email;
this.isActive = properties.isActive;
this.insertedDate = properties.insertedDate;
this.insertedBy = properties.insertedBy;
this.modifiedDate = properties.modifiedDate;
this.modifiedBy = properties.modifiedBy;
this.deletedDate = properties.deletedDate;
this.deletedBy = properties.deletedBy;
this.typeID = properties.typeID;
this.superID = properties.superID;

}

LegalProfessional.prototype = {
fullName: function() {
    return this.lastName + ', ' + this.firstName;
}

};

Trying to resolve the issue of getting 'undefined' for all options when running as per the initial setup. When a breakpoint is added, it seems that the 'this' reference is scoped incorrectly to the HTML element rather than being associated with the LegalProfessional class.

By removing the fullName function from the LegalProfessional class and adjusting the getLegalProfessionals function to manually add fullName, the issue is resolved.

function getLegalProfessionals() {
LegalProfessionalResource.query({isValid: true}).$promise.then(function(legalProfessionals) {
    $scope.supervisors = _.map(legalProfessionals, function(legalProfessional) {
        return new LegalProfessional(legalProfessional);
    });
    $scope.supervisors.forEach(function(supervisor) {
        supervisor.fullName = function() {
            return supervisor.lastName + ', ' + supervisor.firstName;
        };
    });
});

}

Through both approaches, a breakpoint in the controller shows that $scope.supervisors[0].fullName() returns the expected value.

Preferably sticking with the initial method to maintain consistency across multiple areas of the application. Recognize it may be a scope issue with ng-repeat, seeking a solution to address it.

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

Is React failing to identify parameters?

working on my react project, I have an App component which is responsible for rendering multiple child components. Here's how it looks: App render() { return ( //JSX inside <BrowserRouter> <div> <Heade ...

The TypeScript compiler is indicating that the Observable HttpEvent cannot be assigned to the type Observable

Utilizing REST API in my angular application requires me to create a service class in typescript. The goal is to dynamically switch between different url endpoints and pass specific headers based on the selected environment. For instance: if the environmen ...

Is there a way to retrieve two separate route details using jQuery simultaneously?

Clicking the checkbox should display the Full Name: input type="text" id="demonum" size="05"> <button type="button" onclick="load_doc()">click</button><br><br> <input type="checkbox" id ="check" > The r ...

Modules are being installed to the application's root directory using NPM

I made a mistake and have tried everything to correct it, but no success. Every time I run 'npm install' on a new node project, it installs all dependencies in the root of the application instead of the expected /node_modules/ directory. For ex ...

Using jQuery to dynamically insert variables into CSS styles

I am attempting to use jQuery 3 to modify the CSS of a class and change the background color. My first step is converting an rgba color code (properties.color) to a hexadecimal code, which is functioning correctly. Next, I try to change the background co ...

ng filtering with a controller-defined scope

I am currently working on a webpage with AngularJS and I am looking to implement some filters on the site. Here is the HTML code I have: <div ng-repeat="data in datas | filter:{area:course} | filter:{subject:subFilter} | filter:{city:cityFilter}"> ...

Encountering the WRONG_DOCUMENT_ERR: DOM Exception 4 error when attempting to close Fancybox after making edits in inline Tiny

I am encountering a problem with my fancybox that includes a form for collecting user input, which features a tinyMCE editor. When trying to close the fancybox after making substantial edits in the TinyMCE, whether by clicking the close X or submitting the ...

Embed a script into an iframe from a separate domain

While experimenting, I attempted to inject a script inside an iframe element using the following method. However, since the child and parent elements do not belong to the same domain (and I am aware that XSS is prevented in modern browsers), I was wonder ...

Challenge with setting asynchronous default value in React Material UI Autocomplete

Utilizing the 'Material UI' Autocomplete component to show a dropdown in my form. Whenever the user wishes to edit an item, the dropdown should autofill with the corresponding value fetched from the database. Attempting to simulate this scenario ...

The saveAs option in chrome.downloads.download is not working as expected, as it always opens the

I am currently working on an extension that will allow users to download multiple files simultaneously. Using the Chrome downloads API along with AngularJS, here is the code snippet: var fileDownloadProperties = function(raw) { return { url: " ...

Unleashing the Array within a JavaScript Object

Currently, I am successfully receiving messages from a Server via Websocket. The received messages are in the form of a Javascript Object, and my goal is to extract the necessary data from it and update the state of my React app accordingly. Here is the c ...

Safari-exclusive: Google Maps API dynamically altering page aesthetics post-loading

Recently, I encountered a peculiar problem. Upon loading a page, the text displayed with full opacity. However, upon the Google Maps API loading after 2 seconds, the entire page's styling suddenly changed. It was as if the text on the page became less ...

Is there a way to retrieve the `this.$route` data while using vue-apollo?

Currently working on building a GraphQL query with vue-apollo and graphql-tag. When I manually set the ID, everything runs smoothly. However, I'm aiming to dynamically pass the current route's ID as a variable to Vue Apollo. Successful Implemen ...

Utilize module.exports to export objects containing callback functions

I am currently diving into the world of writing my own modules for nodejs. My goal is to create various objects that I can use throughout my application. Here is the result I am aiming for: //assuming we have a database: Person_table(ID int A_I, NAME var ...

javascript show and hide navigation bar

I am currently working on a HTML menu that includes a button to open it and an unordered list : <nav class="menu"> <button> <h1>Menu</h1> </button> <ul class="mylist" ...

How to declare WinJS.xhr as a global variable in a Windows 8 Metro app

Currently, I am developing a Windows 8 Metro app and facing an issue with a hub page. The problem arises when pushing data dynamically from an XML API using two WinJs.xhr("url") calls; one for headings and the other for section datas. When merging both W ...

Modifying the CSS properties of elements with identical IDs

Encountering an issue while attempting to modify the CSS property of elements with similar IDs using JavaScript. Currently, running a PHP loop through hidden elements with IDs such as imgstat_1, imgstat_2, and so forth. Here is the code snippet being emp ...

Tips for transferring form data from a React frontend to the backend Node.js server

I have been attempting to send FormData from React JS to my backend (Express Node server) with the code snippet provided below. However, I am encountering an issue where req.body.myFormData in expressTest.js is showing up as empty. Despite trying various ...

Exploring the intersection of points within an aframe

When working with a point in 3D space, it can be difficult to interact with it using a cursor or mouse. However, in three.js, there is an example (https://threejs.org/examples/webgl_interactive_points.html) where the mouse can easily interact with points ...

Navigate to a different subdomain and place a cookie on the newly redirected subdomain

The version of Express is 4.x NodeJS is running on version 12.x At a.example.com, I have a listener for the GET method that redirects to b.example.com and sets a cookie on b.example.com. app.get('/foo', (req, res) => { res.cookie(' ...