When using $http.get, it retrieves source code instead of displaying HTML content

Just diving into the world of AngularJS. I am using the $http service to make a request for an HTML page from localhost. However, instead of getting the desired result, I'm seeing the source code of the page.

http_service.html

<!DOCTYPE html>
<html>
<head>
    <title>AngularJs | HTTP Service</title>
    <script src="js/angular.min.js"></script>
    <script>
        // Setting up the Angular Application
        var app = angular.module('myApp', []);

        // Creating an Angular Controller
        app.controller('controller', function($scope, $http){
            // Making a request to fetch a page from the remote server
            $http.get('files/myFile.html')
                // Using a success function after initializing the $http object
                .then(function(response){
                    $scope.reqData = response.config;
                });
        });
    </script>
</head>
<body ng-app="myApp" ng-controller="controller">
    <h4>{{reqData}}</h4>
</body>
</html>

files/myFile.html

<!DOCTYPE html>
<html>
<head>
    <title>My file</title>
</head>
<body>
    <h1>Hello from AngularJS by Google</h1>
</body>
</html>

Is there a way to display the heading in myFile.html instead of showing the source code?

Answer №1

Is it possible for you to attempt setting the value by incorporating $sce and modifying the code as shown below?

$http.get('files/myFile.html').then(function(response){
     $scope.reqData = $sce.trustAsHtml(response.config);
});

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

Blur function not performing as anticipated

I am attempting to achieve a blur effect on a dialog pop-up. Currently, I am using the primeng p-dialog component for this purpose. <p-panelMenu [model]="items" [style]="{'width':'300px'}"></p-panelMenu> <p-dialog head ...

How do I utilize Protractor to target a specific div element with a distinctive class and verify its visibility on the page?

Below is the view.html for a unique class: <div class="appExperience small-tile"> </div> This is the code snippet that I attempted to use: var displayedTile = element(by.css('.appExperience small-tile')); expect(displayedTile.i ...

Restricted footage accessible through RESTful API

Hey there! I'm currently working on implementing authentication protected audio/video streaming in an Angular app using REST API. The main objective is to ensure that the audio/video content is secure and not accessible to users who are not logged in. ...

The ComponentDidUpdate function treats the previous state (prevState) and the current state (this

Initially, I had a state update function that looked like this: doChangeValue(data) { const dataNew = this.state.data dataNew[data.id] = data.value this.setState({ ...dataNew, [dataNew[data.id]]: data.value}) } However, I realized that thi ...

There appears to be an issue with the express Router when trying to access the '/page' route

Currently, I am in the process of creating a basic express routing system while utilizing vanilla HTML for the front-end. index.js const express = require('express'), bodyParser = require('body-parser'), serverle ...

Tips for stopping the Bootstrap Modal from appearing every time there is a change event

Currently working on implementing conditional logic for certain products in our store, where a Bootstrap modal is displayed when a specific option is chosen by the user. My understanding of event bubbling is limited, but I have created variables for select ...

Utilizing React JS: Displaying or Concealing Specific Components Based on the URL Path

Is there a way to dynamically change the navbar items based on the URL without having separate navbar components for each side? My current navbar design features 3 links on the left side and 3 links on the right, but I want to display only one side at a ti ...

Include and run a series of scripts in the package.json file

Exploring Node.js for the first time, I find myself in need of adding a series of scripts to package.json and running them one by one. Is this achievable with Node.js? "scripts": { "sample": "run --spec '*spec.js'&quo ...

Questions on how to utilize ES6 Express and static methods

Recently, I've been working with Express and wanted to incorporate ES6 using babel in my project. One question that has been on my mind is related to the use of static methods for handling requests, as shown below: class MyCtrl { static index (r ...

Is there a way to automate the duplication/copying of files using JavaScript?

I have a GIF file stored in the "assets" directory on my computer. I want to create multiple duplicates of this file within the same directory, each with a unique filename. For example: If there is a GIF file named "0.gif" in the assets directory, I woul ...

Overriding values in AngularJS

There seems to be an issue with the code below. Can someone kindly review the image and code provided? The values are not displaying in the correct order as expected, but rather being overridden. The console response in dev tools is accurate, but the UI ou ...

The RadImageEditor onSaving Event does not permit the sending of response scripts

I am using a custom RadImageEditor control with a version of 2013.1.220.40. The control is placed on a page and displayed in a RadWindow. My goal is to either pass a URL or not pass it (for Update and Add scenarios, respectively). After cropping the image ...

Dealing with JQuery and CSS issues on Internet Explorer

Recently, I've been working on a code snippet to maximize a video panel upon page load or resize. Utilizing JQuery 1.4.4, the implementation has been smooth sailing on Chrome, Firefox, and Safari. Drawing inspiration from various online resources, I&a ...

Synchronizing Vuetify Carousel with dynamic route parameters

I'm facing an issue where the v-carousel value does not sync correctly with a route parameter using a computed property. Despite waiting for the mounted hook, the carousel seems to emit its own input and disregard the initial value from the route para ...

Implementing addResponseInterceptor in Restangular's controller allows us to modify

Recently, I've been delving into the world of AngularJS and I've been experimenting with using restangular to access my server's Rest API. The API returns JSON data structured like this: {"Users":[{"AN01_ID":1,"AN01_NAME":"cust1","AN01_REF" ...

The local sending time from the frontend to the backend automatically adjusts and is reduced by 2 hours

When using the DateTime-local in the HTML field to collect datetime from users, I noticed that when sending it to the backend to create an XML file, the date is automatically subtracted by 2 hours for some reason. Despite not making any alterations, and b ...

Locating every quadrilateral within a mesh

I'm currently using Three.js to load a mesh and I am attempting to texture each quad individually. At the moment, I am able to texture each face (triangle), but I am unsure of how to determine if the current triangle and the last triangle are part of ...

Sending an array with a specific identifier through JQuery ajax

I'm facing an issue where I am sending an array of values via jQuery AJAX to my servlet. However, the servlet is only picking up the first value in the array, even though there are more elements present. $.ajax({ type: "POST", url: "mySer ...

I'm encountering an issue while trying to install npx create-react-app. I've attempted to use npm globally as well, but unfortunately, neither option is

While trying to install my React app using npx create-react-app my-app, I encountered the following errors: PS C:\Users\NAEEM UR REHMAN\Desktop\react_app> npx create-react-app my-app npm ERR! code ERR_INVALID_URL npm ERR! Invalid U ...

Utilizing Jcrop on an image loaded via ajax

Recently, I've been working on a project that involves uploading profile pictures to a server and storing them in a database using Ajax. While the basic functionality is working fine, I wanted to enhance the user experience by allowing users to crop t ...