The value of the scope variable remains constant even after selecting a file

After selecting a file, I attempted to change the scope value to the file path.

This is an html file

<input type="file" name="file" onchange="angular.element(this).scope().showFilePath(this)">
<div>{{filename}}</div>

In the controller

angular.module('app')
.controller('UploadFile', function($scope){
    $scope.filename = 'please upload a file'
    $scope.showFilePath = function(file){
    console.log(file.value)
    $scope.filename = file.value
    console.log($scope.filename)
  }
})

When console.log($scope.filename) displays "C:\fakepath\1m.jpg" but on the webpage it still shows "please upload a file".

Any suggestions on how to solve this issue?

Appreciate any help!

Answer №1

Hopefully, you have already tested out this code:


$scope.displayFilePath = function(file) {
    console.log(file.value);
    $scope.filename = file.value;
    $timeout(function() {
        $scope.$apply();
    }, 1000);
}

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

Tips for improving performance with ng-repeat directive?

I have encountered some performance issues while using socket.io with the ng-repeat directive in Angular. The application slows down significantly when receiving a large amount of data from the backend, making it impossible to interact with the app. What w ...

bulk upload with the ability to remove files

I'm in the process of creating a multiple file upload with delete option, similar to the design shown in this image: https://i.sstatic.net/RomOR.jpg I have been following an example on this JS Fiddle demo. My goal is to eliminate the button with the ...

Tips for getting the setTimeout() function to behave like a for loop

Is there a way to achieve the setTimeout() function's behavior in a for-loop? Take a look at this code snippet: function hello() { for (let index = 0; index < 3; index++) { setTimeout(function () { console.log('What&bs ...

HTML and CSS for an off-canvas menu

Looking to create an off-canvas menu that smoothly pushes content out of view instead of cropping it. Additionally, I want to implement a feature that allows the menu to close when clicking outside of it. I found the code for the off-canvas menu on W3Scho ...

Invoking the parent function within ng-include

In my application, I am utilizing ng-include and it seems to be working fine. However, I have some concerns about whether this is the best way to implement ng-include. The HTML within the ng-include file is calling a function from its parent, which makes m ...

Ways to retrieve the $rootScope value from a service function

I am having trouble retrieving the value of $rootScope.exists from the SomeService.getData() function. Even though I can see the value of $rootScope.exists in the rootScope when using console.log outside the function, it shows as undefined when attempting ...

What is the best way to connect the value from ng-repeat in this DIV element to an anchor tag?

I have a template set up like this within my directive: template = '<div ng-repeat="contact in contacts">' + '<a href="www.localhost:3000#/?email=contact.email&phone=contact.phoneno">{{contact.email}}</a>&ap ...

Utilize linqjs to filter an array based on the values present in another array

We have two arrays to work with here. The first array consists of objects: let objectArray = [{ FullName: "Person1", PersonId: "id1" }, { FullName: "Person2", PersonId: "id2" }, { FullName: "Person3", PersonId: "id3" }, ...

React app is having issues with Hammer.js when used together with touch emulator on touch devices

I've been experimenting with testing touch events using Hammerjs in React, and I'm facing quite inconsistent behavior across different browsers and events. Consider this basic code snippet: import React from 'react'; import PropTypes ...

Incorporating a Custom CKEditor5 Build into an Angular Application

I am currently in the process of developing an article editor, utilizing the Angular Integration for CKEditor5. By following the provided documentation, I have successfully implemented the ClassicEditor build with the ckeditor component. Below are the ess ...

Utilize the Autodesk Forge extension button to seamlessly fetch information from an external SQL database

Attempting to establish a connection between my Forge app and an SQL database has been quite the challenge. As someone new to Forge and web development, I'm struggling to navigate the best approach for resolving this issue. I stumbled upon a code snip ...

What is the best way to organize divs in a grid layout that adapts to different screen sizes, similar to the style

Is there a way to align multiple elements of varying heights against the top of a container, similar to what is seen on Wolfram's homepage? I noticed that they used a lot of JavaScript and absolute positioning in their code, but I'm wondering if ...

Ways of transferring ASP.NET MVC view data to an AngularJS controller

I am looking for a way to transfer values from an ASP.NET MVC view (.cshtml) to an AngularJS controller. While I am proficient in AngularJS, I need guidance on how to achieve this in MVC. I have values stored in the MVC cshtml file that I would like to pas ...

Can someone explain the method for displaying or concealing a menu based on scrolling direction?

https://i.stack.imgur.com/tpDx0.jpg I want to hide this menu when scrolling down and show it when scrolling up. The code for my menu bot is: <script> var previousScroll = 0; $(window).scroll(function(event){ v ...

Browser refusing to acknowledge jQuery/JavaScript (bootstrap)

Here is where I include the necessary jQuery libraries and my custom jQuery code: <script src="//code.jquery.com/jquery-1.11.0.min.js"></script> <script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script> <script src= ...

obtaining selections from a dropdown menu and transferring them to an unordered list using jquery

Currently, I am in the process of developing a plugin that transforms select boxes into visually appealing elements. This transformation involves converting select boxes on a page into definition lists, where each definition description contains a nested u ...

Learn the process of playing a video in an HTML5 video player after it has finished downloading

// HTML video tag <video id="myVideo" width="320" height="176" preload="auto" controls> <source src="/server/o//content/test2.mp4" onerror="alert('video not found')" type="video/mp4"> Your browser does not support HTML5 vid ...

Are you initiating several Ajax requests simultaneously?

What is the best approach to updating multiple sections of a page using Ajax? I am working with two divs and two PHP files. My goal is to use jQuery Ajax to populate one div with data received from one PHP file and the other div with data from the second ...

Is it possible to leverage the flex features of react-native in a manner similar to the row/column system of

Is it a good idea to utilize flex in react native by creating custom components that retrieve flex values? I previously used the bootstrap grid system and now I am exploring react native. Is there a way to implement this example using react-native bootstr ...

Tips for setting up a webpacked vue.js application with an express/koa backend!

Struggling with setting up a vue.js project for easy debugging in combination with a koa server? The cross-env NODE_ENV=development webpack-dev-server --open --hot command from the webpack-simple generated configuration looks promising, but how should it b ...