The function was triggered upon the form loading, instead of being activated when the button was clicked

The issue I am facing is that in the code snippet below, the function readCSV() is not being triggered when buttons for filepath1 and filepath2 are clicked. The function is only executed on form load. I was expecting it to work on button click as well.

I would appreciate any assistance with this matter.

Thank you!

<!DOCTYPE html>
<html ng-app="test" ng-controller="homePage">
... (original code snippet) ...

Script section

var test=angular.module("test",[]);
test.controller('submitController',function readCSV($scope, $http){
        var csv = "hello";//$scope.csvPath;
        $scope.filePath1;
        alert(csv);
});

Answer №1

The method in which you defined the controller is incorrect. It is unnecessary to include readCSV within the controller. Also, keep in mind that the controller is automatically initialized when the application loads.

If you want to invoke a function, follow this format:

var sample=angular.module("sample",[]);
sample.controller('submitController',function($scope, $http){
        $scope.readCSV=function(){
          //Perform actions here
        };
});

Answer №2

Give this a shot:

let example = angular.module("example", []);
example.controller('uploadController', function ($scope, $http) {
    $scope.loadFile = function () {
        let file = "world";//$scope.filePath;
        $scope.filePath2;
        alert(file);
    }
});

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

Guide to integrating various HTML files into a single HTML file with the help of Vue.js

Although I am familiar with using require_once() in PHP, unfortunately, I am unable to use PHP in my current project. I attempted to use w3-include from W3Schools as an alternative, but encountered issues with loading my scripts. Even utilizing JavaScript ...

Encountering a problem while trying to install ionic-native using npm

I encountered an error while working with npm and Angular: $ npm install ionic-native --save <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c7a5a8a6b5a3abaea9a287f6e9f7e9f7">[email protected]</a> /home/louisro/Doc ...

Revive the JavaScript library for handling mouse wheel events

Utilizing the wheel-indicator JavaScript library, I am looking to revert the mouse wheel event back to its original state after it was initially set to preventDefault(). Despite attempting to use indicator.setOptions({preventMouse:"false"}) as suggested b ...

Monitoring the "signed in" status within an AngularJS platform

I'm feeling a bit lost as I navigate my way through Angular. As a newcomer, I find myself writing quite a bit of code to keep track of the logged-in state. However, this approach seems fragile and unreliable. Currently, I rely on a global variable to ...

Does the Node Schedule library create new processes by spawning or forking them?

Is the node-schedule npm module responsible for spawning/forking a new process, or do we need to handle it ourselves? var cron = require('node-schedule'); var cronExpress="0 * * * *"; cron.scheduleJob(cronExpress, () => { //logger.info(" ...

"Combining multiple attributes to target elements while excluding specific classes

My dilemma lies in the following selector that identifies all necessary elements along with an extra element containing the "formValue" class which I aim to omit $("[data-OriginalValue][data-OriginalValue!=''][data-TaskItemID]") ...

How can you display a border around a <td> element in an HTML table only when it contains data, using jQuery or JavaScript?

My HTML table consists of the following structure: <table class="table table-bordered"> <thead> <tr> <th>Tag</th> <th>Time Code</th> </tr> </thea ...

Issues with Ionic Toggle displaying incorrect value

I created a basic test using an ionic toggle, but I'm encountering an issue where my alert returns False when the toggle is set to True and True when it's set to false. Any suggestions on how to fix this? http://codepen.io/anon/pen/jtKCf $scope ...

Can you provide a guide on how to retrieve an HTML file using JSON?

There is a problem with fetching files in different formats. Specifically, I want to retrieve an HTML file that needs to be embedded in an iFrame. Currently, my AJAX request only retrieves SWF files. Is there a way to call and fetch the HTML file instead ...

Capturing all requests - javascript

I have a webpage called sample-page.html that contains 2 links: sample-page.html - link1 (GET, AJAX) - link2 (GET, new page) Clicking on link1 triggers an AJAX GET request and remains on the same page (sample-page.html). Clicking on l ...

Dealing with AJAX error in pure JavaScript

I have been attempting to address AJAX errors using the code below, but unfortunately, it does not seem to be effective. function ajaxPost(url, data, success, error) { var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function () ...

Using $index in ng-class to dynamically apply form validation styles

Looking to validate an angular form input and add a class if it's not $valid. The catch is, it's nested inside an ng-repeat looping through an array of integers, with the input name based on the $index: <li ng-repeat="item in selectedItem.dat ...

Developing a Generic API Invocation Function

I'm currently working on a function that has the capability to call multiple APIs while providing strong typing for each parameter: api - which represents the name of the API, route - the specific route within the 'api', and params - a JSON ...

Is it possible to refresh the chat-box using PHP?

I recently created a chat box application using PHP, but I'm facing an issue with its automatic reload functionality. Is there a way to implement auto-reload in PHP itself, or would it be better to restructure the system to utilize AJAX? Additionally, ...

Displaying various Vue components within Laravel 6.x

After diving into Laravel and Vue, I managed to put together a navigation component as well as an article component. The problem I'm facing is that although my navigation vue component is visible, the article component seems to be missing. Reviewing ...

Validation of nested phone numbers using jQuery

I'm trying to figure out how to incorporate the jQuery validation plug-in into a multi-step form where validation occurs on each step as the user progresses. I know that typically, the validation plug-in is triggered by a submit request, but in this c ...

When both input fields share the same directive, scope.$eval() will be undefined

Looking for a way to validate two password input fields and ensure they are equal? (Open to alternative suggestions if my current method is incorrect) I created a directive with basic validation to compare the "confirm" password with the original one. How ...

Change element's parent property's child property into an array form

Question 1: Do you believe that element.property is the same as element[property]? If your answer to question 1 is affirmative, then move on to Question 2: Can you convert element.parentProperty.childProperty into array syntax as explained in question ...

Firebase web authentication is most effective upon the second attempt

I am currently working on a website that interacts with Google's firebase to read and write data. The website has both anonymous and email authentication enabled. Users can view the data anonymously, but in order to edit or write new data, they must s ...

Enforce file selection using AngularJS based on certain conditions

When data is received from the backend in JSON format, it looks like this: { "data":{ "xyz":[ { "number":"1", "short_text":"Sign Contract", "long_text":"Enter names after contract signing", "is_photo":false ...