Verify whether the variable is defined or present within the Angular controller

In my Angular controller, I have the following function:

$scope.sendCompanyData = function() {
    delete $scope.company["step1Form"];
    delete $scope.company["step2Form"];
    delete $scope.standard_address["state"];

    $http.post(Routing.generate('create-company'), {
        'company': $scope.company,
        'standard_address': $scope.standard_address,
        'phone': $scope.phone,
        'courrier_address': $scope.courrier_address,
        'logoFileName': $scope.logoFileName,
        'mercantilDocFileName': $scope.mercantilFileName,
        'rifDocFileName': $scope.rifFileName,
        'standardAddressState': $scope.state.standard_address,
        'standardAddressCity': $scope.city.standard_address,
        'courrierState': $scope.courrierState.courrier_address,
        'courrierCity': $scope.courrierCity.courrier_address
    }).success(function(data) {
        if (!data.success) {
            if (!data.exception) {
                $scope.errors = data.errors;
            } else {
                $scope.errors = data.exception;
            }
        } else {
            $templateCache.removeAll();
            ClientUser.loginToCompany(data.companyId);

            if ($scope.mercantilFileName != "" && $scope.rifFileName != "") {
                $noty.success(Translator.trans('company.register_success'));
            } else {
                $noty.success(Translator.trans('company.register_document_missing'));
            }

            $location.path('/empresa/' + data.companyAlias);
        }
    }).error(function(data, status) {
        $scope.error = status;
    });

    $scope = angular.element($(".seller-layout.new")).scope();
    $scope.section = 'segundo-paso';
}

An issue with this code lies on this line

$scope.mercantilFileName != "" && $scope.rifFileName != ""
as it seems to always pass through the else statement even when there are no values sent. This has been causing me frustration and I'm struggling to figure out what's going wrong. Any suggestions?

Answer №1

Instead of complicating things, why not just use this:

if ($scope.mercantilFileName && $scope.rifFileName) {...}

It seems to me that $scope.mercantilFileName is more likely to be 'undefined' rather than an empty string("").

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 issue arises when attempting to utilize ExpressJS middleware in conjunction with NextJS Link feature

Incorporating Next with Express routes, I have set up a scenario where /a should only be accessible to authorized individuals, while /b is open to the public. ... other imports... const app = next({ isDev }) const handle = app.getRequestHandler() async f ...

What could be the reason for receiving a Firebase INVALID_DYNAMIC_LINK_DOMAIN error message?

I'm having trouble implementing email verification in my React website. Whenever I use the sendSignInLinkToEmail function, I encounter the following error: XHRPOSThttps://identitytoolkit.googleapis.com/v1/accounts:sendOobCode?key=xxxxxxxxxxxxxxxxxxx [ ...

Each div will display the same image twice when loading the image

I have a grid where images are dynamically loaded with a link to a lightbox. Currently, this is how I am achieving it: $(".selection_thumb").each( function(i) { $(this).append("<a data-lightbox='image-1' href='img/folder/folder/"+(++ ...

ReactJS encountering issue with sending POST request, blocked by CORS preflight options

Every time I try to send a POST request to the server, it always responds with an unexpected OPTIONS. My login application built with React and Apollo is experiencing issues. Upon form submission, a mutation should be sent to the server via a POST request ...

What is the most effective method for organizing an object by its values using multiple keys?

I'm interested in utilizing the sort method mentioned in the link but I am facing { "CYLINDER": 2986, "HYDRAULIC": 1421, "JACKS": 84, "INSTALLATION": 119, "REAR": 61, "JACK": 334, "TUBE": 1, "FEED": 114, "ASSEMBLY": 326, "DCS": 2 ...

tips for showcasing an item in a tooltip within a data table

I am working on dynamically creating a table with data retrieved from an ajax response. My goal is to display the data stored in an object within a tooltip attached to each cell. Currently, I have successfully rendered the table, but it is displaying `[obj ...

Deactivating one div's class upon clicking on another div

Below is the HTML code snippet: <div class="container"> <ul class="navbar"> <li class="nb-link"><a>Home</a></li> <li class="dropdown"> <a>CBSE</a> <ul class="dropdown-menu"&g ...

Issue with Laravel: CKEditor text not loading HTML tags

Could you assist me with this? click here for the image description image description available here ...

User-initiated closure of popup triggers error during Google sign in

After successfully implementing Google signin locally, I encountered an issue when attempting to login on a server. The error message displayed was: 'Uncaught: popup closed by user' Despite disabling adblockers and other potential interference, ...

Issue with Angular Factory not being invoked

I am currently using a tutorial to create a MEAN app with Google Maps. However, I have encountered an issue where the map is not appearing on the page. Surprisingly, there are no errors in the browser console and even when debugging with node-inspector, I ...

Using Angular and Laravel to display JSON data extracted from a MySQL database

I am currently retrieving data from MySQL using Laravel query builder, converting it to JSON format as per the suggestion of W3schools. However, when trying to display the fetched data using AngularJS, I end up with a blank page. Laravel route Route::ge ...

Develop a feature within a standard plugin that allows users to add, remove, or refresh content easily

I have developed a simple plugin that builds tables: ; (function ($, window, document, undefined) { // Define the plugin name and default options var pluginName = "tableBuilder", defaults = { }; // Plugin constructor func ...

"Is there a way to adjust the range slider to display currency instead of

I stumbled upon this amazing slider on codepen. Can someone guide me on how to adjust it to display a range from €500 to €6000 while keeping the vibrant red background? I've attempted various solutions like: <input id = "range" type = "range ...

Guide to developing a manual tally counter with recorded logs using HTML and JavaScript

I am currently in need of assistance with creating a manual input counter using the App Script Editor. My website design already includes a single input textbox, a reset button, and a disabled box. What I would like to achieve is that when I enter a numb ...

Avoid repeated appending of data in JavaScript and HTML

I am working with an HTML table and I need to ensure that the values in the second column do not repeat within the grid. Below is the JavaScript code I have written for this purpose: var $addedProductCodes = []; function getProductData(value){ $t ...

What is the reason the child component is not being displayed?

The code within the APP.js component looks like this: import React from "react"; import Exam from "./exam.js"; export default function App() { return ( <Exam> <h1>hashemi</h1> </Exam> ); } Similarly, the ...

What could be causing me to receive 'undefined' and an empty array[] when using Promise.all with JavaScript async operations making calls to Azure APIs?

In my personal project utilizing Azure AI APIs and Node.js/Express,, I am working on handling a get request to a /viewText route by extracting text and key phrases from an uploaded image/document. Below is the code snippet that should log this data to the ...

Is it possible to customize the width of text color alongside a progress bar?

My Bootstrap 4 Website contains the following HTML code snippet: <div class="container"> <div class="row"> <div class="col-md-6 mx-auto> <h2>Example heading text</h2> <h6>Example subh ...

How can I dynamically remove an option from a select dropdown if it already exists in another option using jQuery?

In order to achieve the desired functionality, I need to dynamically adjust the select options based on user input. Additionally, I want the selection to update automatically upon a change event. var dynamicCount = 1; $('#add').click(function ...

Subclass declaration with an assignment - React.Component

I recently started going through a React tutorial on Egghead and came across an interesting class declaration in one of the lessons: class StopWatch extends React.Component { state = {lapse: 0, running: false} render() { const ...