Ways to showcase the ng-cordova camera invoked image on a placeholder

I have 6 product names and images in the server that I am able to display in the UI. The UI looks good, but my requirement is to temporarily display the image (base64 string) in the respective placeholder.

<ul class="list">

           <li class="item" ng-repeat="i in products track by $index" ui-sref="leadProduct" >
                {{i}}
                <br>
                <br>
                <img ng-show="base64Array[$index] != undefined" ng-src="{{'data:image/png;base64,'+base64Array[$index]+imgURI}}" ng-err-src="http://placehold.it/100x100" ng-click="takePicture($index)">
                <img ng-show="base64Array[$index] == undefined" src="http://placehold.it/100x100" ng-click="takePicture($index)">
            </li>
        </ul>

This is how I am currently displaying the array, but below is my ng-cordova camera function:

$scope.takePicture = function() {
    navigator.camera.getPicture(onSuccess, onFail, {
        quality: 75,
        targetWidth: 100,
        targetHeight: 100,
        destinationType: 0
    });

    function onSuccess(imageData) {
        console.log('success');
        $scope.imgURI = imageData;
        $scope.$apply();
    }

    function onFail(message) {
        alert('Failed because: ' + message);
    }
};

I am able to invoke the camera function, but I am unable to view the image that I took from the camera.

Answer №1

attempt,

<img ng-show="base64Array[$index] != null" ng-src="data:image/png;base64,{{base64Array[$index]+imgURI}}" ng-err-src="http://placeholder.com/100x100" ng-click="captureImage($index)">

Answer №2

Just came across this solution and wanted to share. If you're still looking for a fix, here's what worked for me using Ionic View.

//HTML
<ion-content ng-controller="someController">
      <img ng-show="imgURI !== undefined" ng-src="{{imgURI}}" alt="This is not showing">
      <img ng-show="imgURI === undefined" ng-src="placeholder" alt="This is not displaying">
      <button class="button" ng-click="takePicture()" name="button">Take a Picture</button>
  </ion-content>


  //Controller
$cordovaCamera.getPicture(options).then(function(imageData) {
$scope.imgURI = "data:image/jpeg;base64," + imageData;
}, function(err) {
});

The "ALT" attribute may not be necessary for the images, but I like to include it as a best practice.

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

What could be causing the issue with the array.push method not functioning

i have come across this piece of code function fetchImagesList(errU,errorsList) { if(errU) throw errU; var directories=new Array(); var sourceDir=''; var destinationDir=''; if(errorsList==&a ...

Designing an architecture for a Java, Android, and database application - what will the final app's appearance be

I am currently working on a website where users need to complete tasks using an Android device: Fill out a simple HTML document. Sign the document on their Android device. Save the data entered into a database on the website. Some key points to consider ...

Selecting a specific value in Vue.jsNeed help in

My HTML code includes these lines: <v-select v-model="user2_id" :options="[{!! $users !!}]" class="select"> </v-select> <input type="hidden" v-model="user2_id" name="user2_id"> The variable $users is defined as follows: <?php $l ...

Encountering a circular dependency problem in AngularJS due to the use of

I am facing an issue with a circular dependency problem. I created a custom $http interceptor to manage all $http errors and display an alert using a modal from Angular UI-Bootstrap. The chain of dependencies looks like this: $http <- $modal <- Err ...

Look for a specific key value that appears in various parent keys throughout an object in JavaScript

Imagine we have an object that contains information about fruit quantities in different batches: "fruit_quantities" : { "batch1": { mango : 100, apple: 50 }, "batch2": { mango : 0, apple: 50 }, "batch3": { mango : 0, app ...

styling numeric values in user input using React

I developed an Input feature. When the input is a number, I would like it to be formatted properly, such as currency style. For example, 4000 should display as 4,000. Check out the codesandbox here. I am encountering difficulties with displaying and upda ...

Having trouble passing a hook to a child component in a TypeScript project

I am working with a react component that utilizes hooks. The structure of my parent component is as follows: const Parent = () => { const [isEnabled, setIsEnabled] = useState(false); return ( <Child isEnabled={isEnabled} setIsEnabled={s ...

Significant lag in *ngIf caused by the http.get request

<mat-spinner *ngIf="loading === true" class="tableLoading"></mat-spinner> <div *ngIf="loading === false"> ... </div> It's puzzling to me that the spinner takes significantly longer to ...

What is the best way to transmit a variable value from JavaScript to PHP?

I've attempted this method but I am unsure if it's correct: HTML Snippet: <div class="container-fluid"> <form class="form-inline"> <div class="form-group"> <label>Select Number of Records Per Page:</label ...

Adding a disabled internal Style node to the HTML5 DOM: A simple guide

According to this, the style tag can be turned off using the disabled attribute. I attempted the following: <head> <style>body { color: black; }</style> <style disabled>body {color: red; }</style> </head> <bo ...

Encountering an issue where spyOn is reporting a method does not exist error

Running a Karma test on an angular app, the following code is being tested: return inject(function($injector) { this.Service = { functionWithPromise: function(postdata){ var deferred = $q.defer(); deferred.resolve({ ...

The canvas could not be loaded properly in THREE.Texture()

I'm having trouble with adding an image onto the side of a cube that I'm creating. The image loads onto the canvas, but I'm struggling to incorporate it into the texture. function createPictureCanvas(text, font, foreground, background, xres ...

Issue with sticky navbar in parallax design

I have been working on a website where all pages feature a header and a navbar located just below it. As the user scrolls down the page, I want the navbar to stick to the top of the screen once it reaches that position. However, on one specific page, I am ...

Angular Alert: [$injector:modulerr] Unable to create the angularCharts module because: Error: [$injector:nomod]

Although this question has been asked multiple times, the standard solutions provided did not resolve my issue. Therefore, I am sharing my code along with the error in hopes that it will be self-explanatory. Error: Uncaught Error: [$injector:modulerr] Fa ...

Triggering a server-side event handler in ASP.NET using client-side JavaScript

I need help with implementing a countdown timer in JavaScript. When the timer reaches 0 seconds, I would like the page to trigger the button1_click event handler. Here's the scenario: I am working on a quiz engine where the quiz responses need to be ...

Having trouble getting JQuery click to work within an <a> tag?

Here is the HTML code I am using: <a href='someValidLink' class="link"> <img src='imageUrl'/> </a> And this is my JavaScript script: $('.link').click(function(e) { console.log("log something"); ...

What is the best way to open a dialog box in asp.net?

For my asp.net online exam web application, I am looking to implement a confirmation message box or alert when the user clicks on a button to submit the test, fill out user information, or complete other tasks. How can I achieve this functionality? ...

Is there a method to leverage ng-bind for better functionality?

I have created a unique directive that adjusts the size of text in a box to ensure it stays on one line. It works perfectly when the text is received from the server, but I am facing an issue with dynamically generated text from my Angular controller. The ...

Copy the content of one input field into another field at the same time

I have encountered an issue that seems simple, yet the proposed solutions have not been effective. Most suggestions involve using jQuery, but Bootstrap 5 has shifted away from jQuery. I am looking for a solution using JavaScript or HTML only. The problem ...

Adding an additional attribute value or scope model after a directive element can enhance the functionality of AngularJS

Is it possible to create a custom directive that automatically generates a <dd> element following each <dt> element created using the ng-repeat directive? How can I dynamically set the content of the <dd> element to be equal to either a ...