Open the HTML file for this multi-tabbed AngularJS webpage

I stumbled upon this jsfiddle demo code that offers multiple tabs for a single AngularJS webpage.

http://jsfiddle.net/helpme128/99z393hn/

I decided to integrate it into my own project. I specifically wanted one tab to load a particular webpage called my-custom-page.html.

Below are the relevant snippets from my code. Starting with the HTML section;

<div id="tabs" ng-controller="StkViewMainCtrl">
    <ul>
        <li ng-repeat="tab in tabs"
            ng-class="{active:isActiveTab(tab.url)}"
            ng-click="onClickTab(tab)">{{tab.title}}
        </li>
    </ul>
    <div id="mainView">
        <div ng-include="currentTab"></div>
    </div>
</div>
<script type="text/ng-template" id="one.tpl.html">
    <div id="viewOne">
        <h1>View One</h1>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus in varius mauris. Aenean et nisi nec diam dictum maximus.</p>
    </div>
</script>

<script type="text/ng-template" id="my-custom-page.html">
    <div id="viewTwo">
        <h1>View Two</h1>
        <p>Suspendisse potenti. Nullam sodales imperdiet tristique. Proin non rutrum justo, sed venenatis quam. Quisque dapibus risus magna, vel fermentum lacus bibendum ac.</p>
    </div>
</script>

The controller part of the code;

.controller('StkViewMainCtrl', ['$scope', 'configuration',
        function ($scope, $configuration) {
            $scope.tabs = [{
                title: 'One',
                url: 'one.tpl.html'
            }, {
                title: 'Two',
                url: 'my-custom-page.html'
            }, {
                title: 'Three',
                url: 'three.tpl.html'
            }];

            $scope.currentTab = 'one.tpl.html';

            $scope.onClickTab = function (tab) {
                $scope.currentTab = tab.url;
            }

            $scope.isActiveTab = function(tabUrl) {
                return tabUrl == $scope.currentTab;
            }

        }]);

To my disappointment, the desired effect did not occur. The content of my-custom-page.html failed to load even though it is located in the same folder as the main webpage being accessed.

Answer №1

When loading HTML from the main page, you can use something like ng-include to load HTML from another HTML file within a folder. Make sure to update the code as follows:

<script type="text/ng-template" id="my-custom-page.html">
<div id="viewTwo">
    <h1>View Two</h1>
    <p>Curabitur vulputate, ligula lacinia scelerisque tempor, lacus lacus ornare ante, ac egestas est urna sit
        amet arcu. Class aptent taciti sociosqu.</p>
</div>

to

 <script type="text/ng-template" id="my-custom-page.html">
<div id="viewTwo" ng-include="my-custom-page.html"></div>

I made changes to the code and you can view it here on Plunker

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 are the steps to enable a web app on a user's home screen?

Hey there! I'm looking to add a small popup with a button at the end of my website to prompt users to add it to their phone's home screen. I followed a tutorial that helped me achieve this on Android, but unfortunately, it only works with https a ...

Is it possible for me to adjust the size of the Facebook login button on my website?

I have implemented a Facebook login on my website using the following code: <fb:login-button scope="public_profile,email" onlogin="checkLoginState();"> </fb:login-button> Is it possible to replace this button with a standard button or adjust ...

Callback function triggered upon the creation of a DOM node

I am in search of a way to have a specific callback function run each time a div that matches a particular selector is added to the DOM. I have explored the DOM events documentation and the event closest to what I need seems to be "load", however, it does ...

How can I retrieve the current background color and revert it back after a .hover event?

I am trying to use the .hover function to change the background color of a menu. Each menu item has a different background color, so I want it to return to its original color when the user hovers off. In other words, I want the script to read the current b ...

When the button is clicked, the ng-click event will trigger the addClass function, but only on the second click

My bootstrap alert has this structure: <div id="errorAlert" class="alert col-md-6 col-md-offset-3 fadeAlert" ng-if="itemExistsAlert"> <button type="button" class="close" data-dismiss="alert">&times;</button> <p>{{alertM ...

Tips for showcasing the currently active item in a Bootstrap dropdown menu using jQuery

I am trying to highlight the menu item that is selected in a drop-down menu. I attempted the following code, which works if I prevent the default behavior of the link element, but I do not want to do that. So I tried using local storage instead, but it d ...

Display a rectangular shape on an AmChart map using geojson data

Output Example https://i.sstatic.net/BGQ3V.png The output I'm seeing is just a simple rectangle, unlike the maps I create using tools like geojson.io or mapshapper. Strangely, there are no errors showing up in my browser console. My Geojson Data I ...

Leveraging jQuery for Adding Text to a Span While Hovering and Animating it to Slide from Left to

<p class="site-description">Eating cookies is <span class="description-addition"></span>a delight</p> <script> var phrases = new Array('a sweet experience', 'so delicious', 'the best treat', ...

Tips for sending a successful POST request with the MEAN stack

Currently, I am utilizing yeoman to set up a new project. My ultimate goal is to master the process of scaffolding CRUD operations. However, I have encountered an issue with a post request. For this reason, I opted for the angular-fullstack generator as I ...

How can I retrieve the most recent date from a collection of hashes and then extract the corresponding name key/value pair?

I am dealing with an array of hashes structured like this: [ { "Address": 25, "AlertType": 1, "Area": "North", "MeasureDate": "2019-02-01T00:01:01.001Z", "MeasureValue": -1 }, { "Address": 26, "AlertType": 1, "Area": "West", "MeasureDa ...

Upon refreshing the browser, an error pops up saying "unable to set headers after they have been sent."

Error image: https://i.sstatic.net/3dnH9.png app.get('/home', function (req, res, next) { usersession = req.session; if (usersession.loggedin == true) res.redirect('/home'); res.sendFile(path.join(__dirname, &a ...

What is the correct way to incorporate a button into a fullcalendar?

element, I am currently utilizing the full calendar and implementing the following function: calendar: function(data, address){ var self = this; console.info(data); $('#calendar').fullCalendar({ height: 500, events: ...

Child directive of AngularJS fails to initiate when parent directive is using templateUrl

Feeling a bit weary of data grid initialization code, I have decided to experiment with AngularJS. My idea is to define my data grid inline like this: <grid src="http://my/web/service" page-size="10"> <column name="one" label="My First Column ...

Putting a Pause on CSS Transition using jQuery

I am attempting to delay a CSS transition for an element by using a delay function, with an additional 0.2s applied to make it slide 0.2s later than the initial delay of the main wrapper. I am applying a class to give it a transition effect to slide from r ...

Implementing jquery into Angular 2 webpack project is essential as jQuery is necessary for Bootstrap's JavaScript to function properly

I am currently utilizing the angular-cli .net core starter. As I attempt to incorporate my own CSS and JavaScript files, I encounter the following error: An unhandled exception occurred while processing the request. Exception: Call to Node module fail ...

The post() method in Express JS is functioning flawlessly in Firebase cloud function after deployment, however, it seems to encounter issues when running on a

https://i.stack.imgur.com/bIbOD.pngI am facing an issue with my Express JS application. Despite having both post() and get() requests, the post() request is not working on my local machine. It keeps throwing a 404 error with the message "Cannot POST / ...

When using Angular 5's ngModel, the user interface displays the updated value dynamically without requiring the

When filling out my form, I encounter an issue with a select element and a bind variable. If I make a change to the value and save it, everything works as expected. However, if I make a change in a modal window but then close the modal without saving the v ...

Display the value on the screen based on the specified condition

Extracting the "address" value from the backend yields an uppercase result. To format it with only the first letters capitalized, I implemented a solution. However, an issue arises when the "address" value is missing. const capitalizeFirstLetter = (string) ...

Looking to create applications for Android and iOS that can integrate with a module designed in Adobe Captivate

I have created an interactive e-learning module using Adobe Captivate, which has been published in both HTML5 and SWF formats. The module includes some interactive elements/actions that can be accessed by clicking on them. It works perfectly fine in a web ...

Connecting Vue.JS page to my existing HTML page: A step-by-step guide

While developing my website, I faced a challenge with the structure. The home page was built using traditional HTML/CSS, while the other pages were created in Vue.js. Is there a method to connect these two different types of files? For instance, can I inc ...