InfoHeap
Tech tutorials, tips, tools and more
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

AngularJS

  • Hello world
  • ng-init
  • ng-model
  • Controller to increment value
  • Controller - basic clock
  • Controller - ajax
  • date filter
  • include template (url)
  • include template (inline)
  • tabs using ng-switch
  • conditional style using ng-style
  • animation with ng-class
  • ng-if vs ng-hide/ng-show

AngularJS Directives

  • ng-bind
  • ng-bind-html
  • ng-bind-template
  • ng-blur
  • ng-change
  • ng-checked
  • ng-class
  • ng-class-even and ng-class-odd
  • ng-click
  • ng-cloak
  • ng-dblclick
  • ng-disabled
  • ng-focus
  • ng-hide
  • ng-href
  • ng-if
  • ng-list
 
  • Home
  • > Tutorials
  • > Javascript
  • > AngularJS

AngularJS – include inline template

on Mar 14, 2016

Angularjs ng-include can be used to include internal or external (separate url) templates. This tutorial will cover including inline template using ng-include.

ng-include usage

As element:
<ng-include
  src="string"
  [onload="string"]
  [autoscroll="string"]>
...
</ng-include>

As attribute:
<ANY
  ng-include="string"
  [onload="string"]
  [autoscroll="string"]>
...
</ANY>

Example – include inline template as element

Note that since src attribute is a string constant, it needs to be wrapped in single quotes.

<div ng-app="myApp" ng-controller='MyCtrl'>
  <ng-include src="'t1'"></ng-include>

  <script type="text/ng-template" id="t1">
    <b>Hello {{someValue}}!</b>
  </script>
</div>

<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular.min.js"></script>
<script>
var module = angular.module('myApp', []);
module.controller('MyCtrl', function($scope) {
  $scope.someValue = "template t1";
});
</script>
refresh done
try it online

Example – include inline template as attribute

Note that since ng-include attribute is a string constant, it needs to be wrapped in single quotes.

<div ng-app="myApp" ng-controller='MyCtrl'>
  <div ng-include="'t1'"></div>

  <script type="text/ng-template" id="t1">
    <b>Hello {{someValue}}!</b>
  </script>
</div>

<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular.min.js"></script>
<script>
var module = angular.module('myApp', []);
module.controller('MyCtrl', function($scope) {
  $scope.someValue = "template t1";
});
</script>
refresh done
try it online

Suggested posts:

  1. AngularJS – include url template
  2. AngularJS ng-bind-template example
  3. HTML5 template tag hello world tutorial
  4. How to include angularjs javascript in wordpress post
  5. AngularJS – implement tabs using ng-switch
  6. How to include bootstrap javascript and css in wordpress post
  7. AngularJS – dynamic css using ng-style
  8. AngularJS format date using date filter
Share this article: share on facebook share on linkedin tweet this submit to reddit
Posted in Tutorials | Tagged AngularJS, Javascript, Tutorials

Follow InfoHeap

facebook
twitter
googleplus
  • Browse site
  • Article Topics
  • Article archives
  • Recent Articles
  • Contact Us
  • Omoney
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries

Copyright © 2023 InfoHeap.

Powered by WordPress