Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embedding Html page using Angular js

I'm new to Angular js and I'm trying to use Angular js to embed html snippets within a html page with the help of bootstrap template.

This is my index.html

<body >
  <div ng-app="">
     <div ng-include="mainmenu.html"></div>


       <!-- Page Content -->
          <div class="container">

         <div class="row">
            <div class="col-lg-12 text-center">
               <h1>Starter Template</h1>
                <p class="lead">Complete with pre-defined file paths that you won't have to change!</p>

           </div>
         </div>
    <!-- /.row -->

    </div>
<!-- /.container -->
 </div>
  <!-- jQuery Version 1.11.1 -->
  <script src="js/jquery.js"></script>

  <!-- Bootstrap Core JavaScript -->
  <script src="js/bootstrap.min.js"></script>
  <script  src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
</body>

This is my manimenu.html

<!-- Navigation -->
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
    <div class="container">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="#">Start Bootstrap</a>
        </div>
        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav">
                <li>
                    <a href="#">About</a>
                </li>
                <li>
                    <a href="#">Services</a>
                </li>
                <li>
                    <a href="#">Contact</a>
                </li>
            </ul>
        </div>
        <!-- /.navbar-collapse -->
    </div>
    <!-- /.container -->
</nav>

Both index.html and mainmenu.html are in same folder. But mainmenu.html is not showing inside the index.html. If anyone knows please help me to solve this

like image 655
Raj Avatar asked Jul 08 '16 10:07

Raj


People also ask

How can you integrate AngularJS with HTML?

AngularJS extends HTML with ng-directives. The ng-app directive defines an AngularJS application. The ng-model directive binds the value of HTML controls (input, select, textarea) to application data. The ng-bind directive binds application data to the HTML view.

Can we use HTML in angular?

With AngularJS, you can include HTML from an external file.

HOW include external HTML file in AngularJS?

Following is code from angular component to import external html. http. get('assets/included. html', { responseType: 'text' }).

What is AngularJS How does it work with HTML?

AngularJS is a structural framework for dynamic web apps. It lets you use HTML as your template language and lets you extend HTML's syntax to express your application's components clearly and succinctly. AngularJS's data binding and dependency injection eliminate much of the code you would otherwise have to write.


2 Answers

All you're missing is quotes around the reference to your template. Without quotes, it's evaluated as an expression.

<div ng-include="'mainmenu.html'"></div>

From the documentation

angular expression evaluating to URL. If the source is a string constant, make sure you wrap it in single quotes, e.g. src="'myPartialTemplate.html'".

like image 158
robstarbuck Avatar answered Sep 28 '22 09:09

robstarbuck


.try with this or checkout the link below

<div ng-include src="'mainmenu.html'"></div>

http://stackoverflow.com/questions/13943471/angularjs-ng-include
like image 40
Sa E Chowdary Avatar answered Sep 28 '22 08:09

Sa E Chowdary