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

Using the React UseEffect Hook allows for value updates to occur within the hook itself, but not within the main

I am currently utilizing a font-picker-react package to display fonts using the Google Font API. Whenever a new font is chosen from the dropdown, my goal is to update a field value accordingly. While the 'value' updates correctly within the ...

Confirmation message is displayed upon clicking to delete a row in the editable Gridview, prompting the user to

One issue I am facing is with a Delete button in an editable Gridview on my ASP.NET application. When the delete button is clicked, it triggers a function that displays a confirmation popup asking the user for feedback on whether they want to proceed with ...

What is the best way to utilize "require" dynamically in JavaScript?

Within the "sample.js" file, there is a JavaScript function structured as follows: var mapDict = { '100': 'test_100.js', '200': 'test_200_API.js', '300': 'test_300_API.js' } function mapAPI() { ...

What is the best way to make multiple HTML tables sortable?

I recently implemented an open-source JavaScript table sorter in my project. You can find more information about it here: However, I encountered an issue where only the most recently added table on my page is sortable. When users press a button, new table ...

Unable to conceal element if it is devoid of content

<div id="web-link" class="infoline"> <i class="fa fa-link fa-2x fa-fw coloriconfa"></i> <a href="<?=$data['post']['url']?>" target="_blank"><?=$data[ ...

Explore the properties within an array of objects through iteration

Here is the array I'm working with: const myArray = [{ id: 1, isSet: true }, { id: 2, isSet: false }, ...]; I only need to iterate over the isSet properties of the objects, ignoring all other properties. Initially, I attempted the following solution ...

Material-UI: The call stack has exceeded the maximum range, causing an Uncaught RangeError

I am currently utilizing the Dialog and Select components offered by Material-UI in conjunction with React. Here is a quick example: import React from 'react'; import { Dialog, MenuItem, Select } from '@material-ui/core'; class Examp ...

The rating system does not accurately incorporate the values provided by the API

Incorporated the star rating package into my ReactJS code to showcase the star value retrieved from a mock API. import { Rating } from "react-simple-star-rating"; However, when attempting to make it read-only, it does become static but fails to ...

Issues with onClick events not triggering on transformed CSS3 elements

//My mind was completely tangled up. Everything is functioning properly, this question is inaccurate and outdated When I rotate an Element on the Y-axis and attempt to click on it, which has a bound eventListener (onClick), the event does not trigger (hov ...

The Hidden Div containing NicEdit is now shrunk down to a smaller size

Attempting to integrate the NicEdit editor for a hidden textarea stored within a div has presented some challenges. The goal is for the targeted textarea's parent div to be revealed upon the user clicking a button, with the textarea's width set t ...

Creating a Modal Dialog with Justified Tab and Dropdown Using Bootstrap 4.1

I am struggling with Bootstrap 4.1 as I try to align content to the right side. Specifically, I have a Navigation Bar that triggers a Modal Dialog containing Tabs. The dropdown menu on the far right of the Tab is what I want to justify to the right. Here a ...

Angulajs: The correct way to simulate a Promise received from $http

Seeking guidance after struggling with unit testing an angular service, specifically the failed part of a promise. (function () { angular.module('testable') .factory('myService', ["$http", "$q", function ($http, $q) { retur ...

Is it possible to send an email with an attachment that was generated as a blob within the browser?

Is there a way to attach a file created in the browser as a blob to an email, similar to embedding its direct path in the url for a local file? The file is generated as part of some javascript code that I am running. Thank you in advance! ...

What is the process for displaying HTML page code received from an AJAX response?

My current project involves implementing JavaScript authentication, and I have a specific requirement where I need to open an HTML file once the user successfully logs in. The process involves sending an AJAX request with the user's username and passw ...

Create a hover effect on HTML map area using CSS

Is it possible to change the background color of an image map area on hover and click without using any third-party plugins? I attempted the following code: $(document).on('click', '.states', function(){ $(this).css("backgro ...

How can I dynamically set the width of a span element in HTML?

Hello there! As a beginner in html and angularjs, I'm experimenting with dynamically assigning span width based on an angular js response. <div class="statarea" ng-repeat="x in names"> <div class="ratingarea"> <div class=" ...

Display additional javascript code for expanding a marquee

Currently, I am working on a stock ticker project using JavaScript. It's progressing well, and now I am focusing on adding a "show more" button to style the ticker. The button should be placed outside of the marquee. When clicked, it will expand the m ...

A guide on incorporating a React custom package within an Angular directive

Hey there, I have an Angular v1.x application and a React custom package. I'm looking to integrate the React custom package into my Angular directive, so that it can display a React component. Here's some code snippet: Angul ...

Struggling to accurately convert the string into a date object

I have an array of objects structured like this: const days = [ { _id: 12312323, date : '30/12/2021', dateStatus : 'presence' }, ... ] I am looking to convert the date property from a string to a Date object using the follo ...

Extracting information from a Postgres query in Node.js

I'm looking for guidance on how to pass the results of a postgres query in Node.js to another function. Can anyone provide an example? ...