Activate a function after selecting a file using the input type=file and showcase the file path by utilizing ng-repeat

  <input type="file" id="file" name="file" ng-show="attachFile" />
  <button type="button" ng-model="attach" ng-click="add()">Attach</button>

  <div class="panel panel-default" ng-show="displayAttachments">
    <div class="panel-heading">
      <h3 class="panel-title">Attachments</h3>
    </div>
    <div class="panel-body">
      <ul class="list-group">

        <li class="list-group-item">C:\fakepath\angularjs_tutorial.pdf</li>

        <li class="list-group-item">display file path using ng-repeat in this panel</li>

      </ul>
    </div>
  </div>

I have a button named attach that triggers the add() function from my controller, which shows the input field of type file. The functionality is

  • Show the choose file button(input type=file) when the attach button is clicked
  • after selecting a file, hide the choose file button and show the attachment field
  • Display the file path in the li tag of the attachment field using ng-repeat
  • Allow uploading another file next to the existing files, with the path of the new file appearing below the path of the previously selected file

The code in my controller is as follows:

$scope.attachFile = false;
$scope.displayAttachements = false;
$scope.add = function() {
  $scope.attachFile = true;
}

Answer №1

Take a look at this solution I believe it can be useful as there is no direct binding for file input attribute

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 functionality of cloning in jQuery may encounter an issue where the text field remains enabled if the user selects an option labeled "other

Currently, I am working on a jQuery clone with my existing code and everything is functioning well. In the first scenario, if the user selects other from the dropdown menu, the text field becomes enabled. In the second scenario, when the user clicks ...

Position the mat-icon button in the top right corner for the close button

I'm struggling with positioning my close icon button at the top right corner of my dialog box. Here is my app-iconbutton component: <button mat-icon-button class="iconbutton" [ngStyle]="{ 'background-color': back ...

When utilizing an object as state in React, the `setState` function will only set

Currently, I am working on developing a React form that utilizes a custom Input component which I have created multiple times. The objective is to gather all the names and values from the form in the parent component: {inputName: value, inputName2: valu ...

Error encountered when attempting to upload an attachment in Sharepoint, resulting in a

Whenever I attempt to upload multiple attachments to my list, I encounter a 'save conflict' error. It seems that Sharepoint is still processing the previous attachment when a new one is submitted. I believe that introducing a delay before sendin ...

Maximizing Bootstrap card size in Angular4: A step-by-step guide

How can I make Bootstrap cards resizable on top of other elements when clicked on an icon to make it full screen and overlay on other cards? detail.component.html <div class="card card-outline-info" > <div class="card-header bg-info"><h5 ...

The column flex-direction property seems to be malfunctioning

Can anyone help me with styling a ul tag using display: flex? I'm trying to order it by column with flex-direction: column;, but for some reason, it's not working. Here is the CSS code for the container: #nav li.four_columns ul.sub-menu { widt ...

css background-size and image position not working

On my website, users/members can upload or link a custom image for the start page. This feature works well with modern browsers that support background-size in CSS. However, if the browser does not support css3 background-size, the image may not fill the e ...

I am currently facing an issue with my Next JS app where the search results page is not showing up when a user enters a query

I am currently working on a search application using Next.js. Within my app directory, I have 3 main files - layout.js, page.js, and searchResults.js Here is the code in layout.js: export const metadata = { title: 'xyz Search', description: ...

Successful Ajax response notification

I am new to using ajax and I want to implement a .post method with an if condition to notify the user of its success or failure. Here is my code for .post: $.post("ajaxRegistering.php",{ name: name, lastname: lastname, ...

Load and Activate Element

I am utilizing Bootstrap 4 features and some custom settings in my elements. <div class="btn-group btn-group-toggle" data-toggle="buttons"> <label class="btn btn-outline-selector make-active"> <input ...

Having trouble sending data through a jQuery AJAX request?

When I make a post request using jQuery AJAX to an ActionResult method, I encounter the following issue: $("#itemTextbox, #itemTextboxNew, #quantity1Textbox").on("keydown", function (e) { if ((e.keyCode == 120){ var GetReportLast5SellAndBuyURL="/Trd/Se ...

Error in Internet Explorer when attempting to close a Fancybox iframe that plays a YouTube video

Even the FancyApps page itself contains the error mentioned below. If you visit using Internet Explorer 9, for example, follow these steps: Go to Internet Options > Advanced > Disable script debugging (Internet Explorer). Then click on the YouTube ( ...

Enhance the responsiveness of a ReactJS landing page

We have developed a large React application without relying on any existing UI framework. All of our UI components have been custom-built. Now, we are looking to make the landing page section responsive within the application, which will require the imple ...

unusual behavior observed in addEventListener

I have recently delved into learning about the DOM. I have a project in mind where I want to create a website with buttons that, when clicked, play different drum sounds. As part of my experimentation with JavaScript, I wanted to explore the this keyword. ...

Issue: Catching errors in proxy function calls

I am currently using Vue 3 along with the latest Quasar Framework. To simplify my API calls, I created an Api class as a wrapper for Axios with various methods such as get, post, etc. Now, I need to intercept these method calls. In order to achieve this ...

Leveraging the power of the babel standalone tool to utilize imports in

Trying to execute React in Babel-standalone and implementing imports from neighboring files is my current dilemma. I am inclined to avoid using a bundler and prefer solutions that strictly involve import/export. Below is a brief example of the issue: i ...

Unable to open javascript dialog box

One issue I encountered involves a jqGrid where users have to click a button in order to apply any row edits. This button is supposed to trigger a dialog box, which will then initiate an ajax call based on the selected option. The problem lies in the fact ...

What is the best way to loop through properties of a Typescript interface?

I am currently working with an interface called FilterData, which has the following structure: export interface FilterData { variables?: string[]; processDefinitionKey?: string; } When I make a request to the server, I receive an object named filterS ...

Utilizing Angular's ng-show feature alongside an AJAX request to retrieve specific information

As a newcomer to Angular, I am currently working on setting up a notification list. The concept is straightforward - a summary of notifications is shown and when clicked, the details of the notification appear. You can see what I've done so far in thi ...

Add some TD(s) after the td element

The HTML code I currently have is as follows: <tr> <td class="success" rowspan="1">Viability</td> <td data-rowh="-Checksum">Viability-Checksum</td> </tr> <tr> ...