Issue with displaying navigation bar while utilizing ng-include in AngularJS without reliance on bootstrap

I am attempting to develop a navigation bar that will be displayed on every page by using ng-include as a reference. While the navbar functions properly on its own, it is not appearing on the pages where I am trying to include it (example: the dashboard). I have opted not to use Bootstrap in order to build it from scratch for educational purposes. I suspect there may be a misunderstanding of how AngularJS operates?

Here is the current code snippet:

dashboard.html:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <link rel='stylesheet' href='dashboard.css'>
    <title>Dashboard</title>
  </head>
<body ng-app='MyApp'>

    <nav class="navbar"><div ng-include src="'navbar.html'"></div><p>Hi!</p></nav>

<div class='dashboard'>
  Here be contents
</div>

  <script src="bower_components/angular/angular.js"></script>
  <script src="bower_components/angular-route/angular-route.js"></script>
  <script src="app.js"></script>
  <script src="view1/view1.js"></script>
  <script src="view2/view2.js"></script>
  <script src="components/version/version.js"></script>
  <script src="components/version/version-directive.js"></script>
  <script src="components/version/interpolate-filter.js"></script>
</body>
</html>

navbar.html:

<!DOCTYPE html>
<html >
  <head>
    <meta charset="utf-8">
    <link rel='stylesheet' href="navbar.css">
  </head>
<body ng-app='MyApp'>

<nav class='navbar'>
  <ul>
    <li><a href="../app/dashboard/dashboard.html">Home</a></li>  
    <li><a href="app/other.html">Temp</a></li>


  </ul>    




</nav>


  <script src="bower_components/angular/angular.js"></script>
  <script src="bower_components/angular-route/angular-route.js"></script>
  <script src="app.js"></script>
  <script src="view1/view1.js"></script>
  <script src="view2/view2.js"></script>
  <script src="components/version/version.js"></script>
  <script src="components/version/version-directive.js"></script>
  <script src="components/version/interpolate-filter.js"></script>
</body>
</html>

navbar.css:

.navbar {
    font-family: Arial, sans-serif;
    font-size: .9em;
}
.navbar ul {
    list-style-type: none;
    overflow: hidden;
    margin: 0;
    padding: 0;
    background-color: lightslategray;
    position: fixed;
    top: 0;
    width: 100%;
}
.navbar li {
    float: left;    
}
.navbar a {
    display: block;
    text-decoration: none;
    cursor: pointer;
    padding: 14px 16px;
    text-align: center;
    background-color:lightslategray;
    color: white;
}
.navbar a:hover {
    background-color: darkslategrey;
}
.active {

}

Answer №1

When creating your navbar template, it's important to remember that it shouldn't be a separate HTML page. Instead, you are simply injecting markup, so the file should contain code as it would normally be written.

The navbar.html file should only include:

<nav class='navbar'>
  <ul>
    <li><a href="../app/dashboard/dashboard.html">Home</a></li>  
    <li><a href="app/other.html">Temp</a></li>    
  </ul>
</nav>

Answer №2

Consider omitting the single quotes from navbar.html and double-check that navbar.html is present in the identical folder as dashboard.html. If it's located in another directory, you need to indicate its specific location.

Answer №3

To begin with, it is imperative that ng-include contains only the necessary code for that specific section, such as just the <nav> </nav> tag.
Furthermore, the absence of including navbar.css in dashboard.html is why the navbar fails to display.

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

Embracing the cutting-edge technology of the Wordpress revolution slider for an HTML

Is it possible to integrate the WordPress Revolution Slider into a website without using WordPress (just HTML and CSS)? I've attempted to search for JavaScript solutions, but there are too many scripts available. ...

"Running experiments with Google Ads and Google Analytics scripts results in a blank page being displayed

Currently, I am working on a plain HTML file and conducting tests to ensure that the Google Ads and Analytics scripts are functioning correctly before implementing them on other pages. A colleague who has an AdSense account provided me with the script code ...

What is the best way to link JavaScript files from a Grails plugin in a separate Grails application?

I have developed a unique plugin that offers multiple Grails controllers and domain objects. Additionally, I have created several AngularJS UI components that I wish to utilize in various other projects. These specific files are located within the web-app ...

Problem arises with the HTML/CSS tab on hover or when it is in active state

I am encountering a problem with a tab. The link is provided below for reference: <div class="dm-main-tab-menu"> <ul> <li class="Content active"><a accesskey="1" href="?content">Content</a></li> < ...

Internet Explorer is not honoring the max-width property when used in a select tag

When I use a select tag with a style of max-width: 150px, it works in FF but not in IE. So, I changed max-width to width: 150px and it works in both browsers. However, in IE, the text is truncated. Can anyone help me with this issue? Am I doing something ...

JQuery: Dealing with Toggle Problems

My goal is to create a toggle effect for a slidediv using a link, but I'm facing issues when trying to implement the same functionality in another form or <div>. The tooltip div fails to work in those scenarios. JavaScript: <script typ ...

React Suspsense fails to load the stylesheet

I'm currently working with the following code snippet. <Suspense fallback={<span />}> {theme === "dark" ? <DarkTheme /> : <LightTheme />} </Suspense> DarkTheme Component import React from "react"; i ...

When the div reaches the top of the viewport window, call this function

Can you review the code snippet below? I need a function to trigger when the red box's top aligns with the viewport during scrolling. JS Fiddle: http://jsfiddle.net/ay5ttmLk/ HTML <div class="test" style="height:100px;width:70px;"> sadfsadf s ...

Is the WordPress error message "wp_register_style was improperly called" showing up on

I am facing an issue while trying to incorporate this code into my initial Wordpress template. It seems that the libraries for Bootstrap and my custom styles are not functioning as expected. Here is the code snippet in question. Any insights would be great ...

What is the best way to ensure my website page fits the browser window properly?

I'm currently working on my portfolio page for a class project. I want to make sure that the webpage adjusts properly when the browser window is resized, particularly the navigation links in the header section. When the screen is in full view, the nav ...

What is the best way to expand the width of my Bootstrap 4 navbar dropdown menu?

Need help creating a full-width dropdown for a Bootstrap 4 navbar using the standard boot4 Navbar? Check out the navbar template I am currently working with. Here is an example of how I want it to look: Desired design image link <nav class="navbar fix ...

Manipulating Objects with CSS Transform in Global/Local Coordinates

If we take a closer look at our setup: <div id="outside"> <div id="inside">Foo</div> </div> and apply a rotation to the outer element - let's say turning it 45 degrees clockwise: <div id="outside" style="transform: ro ...

Tips for showcasing the contents of a file on a website

Greetings! I am a newcomer to the world of web development and I am seeking a method to showcase file content on a webpage. Presently, I have succeeded in loading text file content and displaying it in a large text box. However, I am now interested in di ...

Adjust the height seamlessly on the homepage without the need for scrolling, while maintaining a stationary navigation bar and footer

Our latest project is designed specifically for mobile use. The fixed navigation bar is functioning perfectly. We also have a fixed footer with icons at the bottom. (All working well) The challenge we are facing is to make the content between the naviga ...

Incorrect placement of rectangle on a dynamic canvas

After clicking on two different positions on the canvas rectangle, I noticed that it was being drawn in the wrong location due to issues with the responsive canvas size. Despite attempting to scale the pointer position based on both the canvas and window w ...

Incorporating text onto an HTML webpage

Context: My program reads a file and displays it on an HTML page. The code below utilizes regex to extract errors from the file. Instead of using console.log for debugging, is there a way to display the results on the HTML page? When attempting: document ...

After the angular js quickstart, the error message 'Backand is undefined' appeared

Each time I attempt to utilize a basic CRUD action, this error seems to arise. An issue: Backand has not been defined I followed all the instructions diligently as per their request, yet something appears to be amiss and I am unable to pinpoint it... t ...

What is the best way to adjust the placement of this object so it is anchored to the left side?

https://i.sstatic.net/k8aF1.png I'm struggling to position one of my divs more to the left within a flex container. No matter what I try, changing the class of the div doesn't seem to have any effect. Here's the code snippet: import React f ...

Exploring composite search conditions in MongoDB with JavaScript

Being a newcomer to Node JS and mongo DB, I am currently working on a project that involves fetching data from mongo db using a JavaScript file. The challenge I am facing is to search multiple columns in order to retrieve the desired results. Initially, w ...

The color of the left arrow on the tooltip cannot be altered

Currently, I am using a tooltip that is positioned on the right side: <i class="fas fa-question-circle text-blue" data-toggle="tooltip" data-placement="right" title="hello" ></i> I have attempted to modify the color of the too ...