The initial viewing of a base64 image in SVG format may not render properly on the first attempt

Currently, I am in the process of developing a hybrid application using cordova.

Interestingly, I have encountered a situation where I need to store an SVG image containing a base64 image and some text in my SQLite database. The format in which I saved the SVG source text is like this:

<svg xmlns="http://www.w3.org/2000/svg" width="400" height="300" style="margin-top:5px;text-align:center" class="ng-scope">
  <foreignObject width="100%" height="100%"><div xmlns="http://www.w3.org/1999/xhtml" style="width: 390px;height: 290px;background-color: #2B6E44;padding: 4px">
    <table style="width:100%;height:100%;border-collapse:collapse;border:2px solid white;color:white;font-size:1em">
      <tbody>
        <tr>
          <td colspan="2">
            <div class="forImg" style="height:100%;width:50%;float:right">
              <img ng-src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAgAAZABkAAD/7AARRHVja3kAAQAEAAAAZAAA/+4ADkFkb2JlAGTAAAAAAf/.............  
                ..........................................
               L0JEX//Z" style="display:block;max-width:180px;max-height:170px;width:auto;height:auto;" />
            </div>
          </td>
        </tr>
      </tbody>
    </table>
  </foreignObject>
</svg>

Despite following this format, when retrieving this value from the database and setting it as the src attribute of the img element using JavaScript:

JS:

$scope.blackboard.svgSource = "data:image/svg+xml;utf8," + res.rows.item(i).svg_source;

HTML:

<img ng-src="{{blackboard.svgSource}}"/>

The table in the SVG displays correctly, but the base64 image does not load until it has been displayed once on another page (where all the pictures are placed into the SVG).

Considering that the image in the SVG can be shown after being displayed on another page, I believe the base64 data is correct.

However, I am puzzled as to why it doesn't show up the first time around?

I would greatly appreciate any assistance!

Answer №1

Apologies for posing the initial question, but I have since managed to resolve it independently.

Upon reflection, it appears that using SVG with a base64 image embedded in the src attribute of <img> is not ideal.

I ultimately discovered that the ng-bind-html directive in angularJS is perfectly suited to my scenario, as it allows for inline SVG creation. This approach ensures that the base64 image is displayed correctly from the outset.

If this topic interests you, I recommend checking out:AngularJS : Insert HTML into view

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

Importing JSON Data into an HTML File

I need to load a JSON file containing HTML content into my main HTML file upon clicking a button. ABC.json includes: <li><img src="images/picture6.jpg" /></li> <li><img src="images/picture5.jpg" /></li> <li><i ...

The React application deployed on GitHub Pages is displaying a blank white screen

I developed a simple meme generator app in React.js as an exercise to learn web development, but I am facing issues while trying to host it on Github pages. I followed all the necessary steps such as installing gh-pages with node, updating packages.json wi ...

Revolutionizing the Industry: Discover the Power of Dynamic Models, Stores, and Views for

As a newcomer to EXT JS, I am exploring the use of MVC in my projects. Consider a scenario where I have a web service with a flexible data model. I would like to dynamically create models, stores, and components based on the data from these stores. Let&a ...

Transform array of objects into a two-dimensional array

Is there a way to transform the following group of objects into a 2D array? var tags= [ {id: 0, name: "tag1", project: "p1", bu: "test"}, {id: 1, name: "tag2", project: "p1", bu: "test"}, {i ...

Why does the outcome of running this code vary each time?

I've been working on a code project to create 10 bouncing balls of different colors, but I'm encountering an issue where only one or two balls appear with different colors or the animation works perfectly only 1 out of 10 times. Any thoughts on w ...

Encountering a problem involving the apostrophe character "'" when trying to save content into a MySQL database

I have been developing an application that allows users to create HTML templates and save them. Users can utilize different components such as text, images, etc. to build HTML pages. Challenge: The issue I'm encountering is when a user inputs text wi ...

When making an AJAX call on MS Edge, the response data variable unexpectedly populates with source code instead of the server's sent data

I've encountered a bizarre issue that seems to be exclusive to MS Edge and affects only certain users at one particular client. When making an ajax call to the server, instead of receiving the expected response data, it appears that some source code f ...

Function activation in Element requires a double click to initiate

I've encountered an issue with a web element I'm working on where the click function only triggers after the first click, rendering the initial click ineffective. Here's the code snippet in question: HTML: <div> <a href="#0" cla ...

trigger a CSS animation using JavaScript upon a specified event

I am attempting to incorporate a class for an autogrow animation effect to a textarea element. Here is a demo: http://jsfiddle.net/d0kmg7d3/15/ var tx = document.getElementsByTagName('textarea'); for (var i = 0; i < tx.length; i++) { tx[i] ...

When running "npx create-nuxt-app" followed by "npm run dev", an error occurs stating that there

Recently, I started using Nuxt and initiated my app with npx create-nuxt-app my-app, setting the parameters as follows: Project name: client Programming language: JavaScript Package manager: Npm UI framework: Tailwind CSS Nuxt.js modules: Axios - Prom ...

What causes a function to be returned as null when it is appended or assigned as textContent?

There's something I've been trying to figure out and I'm curious to get an answer on why it behaves this way. const print_html = (param) => { let container = document.querySelector('Container'); console.log(test_function(pa ...

Techniques for utilizing ng-class to merge class attributes

I'm new to Angular and I want to combine classes using ng-class. Specifically, I'd like to use the save class along with the firstClass class if something = First. I've been doing some research on how to implement this with ng-class but I ha ...

Executing a function from within a promise in JavaScript

Understanding the Code In this code snippet, there is a function named placeDecode that takes an HTML input element as a parameter. Inside this function, there is a promise used to convert the input value into a formatted address. The function placeDecod ...

Is an empty string equivalent to false in a boolean context?

I would appreciate further clarification on this subject. I have read several articles, but none have fully answered my questions. ...

What is the best way to retrieve the value of a URL parameter using javascript?

I need help extracting the value of a specific parameter from a list of URLs. Here are some examples: http://example.com/#!/dp/dp.php?g=4346&h=fd34&kl=45fgh&bl=nmkh http://example.com/#!/dp/dp.php?h=fd34&g=4346&kl=45fgh&bl=nmkh ht ...

Reading a file in Javascript as it is being written: Techniques and methods

Let's consider a scenario where there's a log file, or in my situation, a binary data file. (I'm extracting data to create real-time stripcharts.) I want to read the entire file and perform operations on it, then have my FileReader trigger a ...

How can I retrieve properties from a superclass in Typescript/Phaser?

Within my parent class, I have inherited from Phaser.GameObjects.Container. This parent class contains a property called InformationPanel which is of a custom class. The container also has multiple children of type Container. I am attempting to access the ...

The function queryDatabases is not supported in the DocumentDB JavaScript API

Currently, I am developing a service for Azure Functions using JavaScript/Node.js. However, I encounter an error when trying to access the function DocumentClient.queryDatabases. Despite having the correct references installed in Visual Studio Code and bei ...

Sliding with jQuery to eliminate a div element

I wanted to dive into jQuery and decided to recreate the slick animation from Jay-Z's new album commercials. In these ads, a bar slides left over his name while simultaneously disappearing. I also wanted to add a flashing effect by fading out, fading ...

No content is shown when the div height is set to 100%

My div content is being loaded from a PHP file (total of 15 items) using jQuery. When the height of the div reaches 500px, all the content is displayed perfectly. However, when I try to set the height to 100%, some of the data is missing. The rest of the ...