Skip to content

Instantly share code, notes, and snippets.

@ovarunendra
Last active August 29, 2015 14:07
Show Gist options
  • Save ovarunendra/84ce0722b3d527fbbb42 to your computer and use it in GitHub Desktop.
Save ovarunendra/84ce0722b3d527fbbb42 to your computer and use it in GitHub Desktop.
simple ng-include example
/**
* Created by ovarunendra on 05-10-2014.
*/
// Code goes here
angular.module('MyApp', [])
.controller('MainCtrl', [function() {
var self = this;
self.template = 'first.html';
self.change = function(){
self.template = 'second.html';;
};
}]);
<h1>First Template</h1>
Name: <input type="text" ng-model="mainCtrl.name"></input>
<button ng-click="mainCtrl.change()">Save</button>
<!DOCTYPE html>
<html>
<head>
<title>Sample App</title>
</head>
<body ng-app="MyApp">
<div ng-controller="MainCtrl as mainCtrl">
<div ng-include="mainCtrl.template">
</div>
</div>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular.js"></script>
<script src="app.js"></script>
</body>
</html>
<h2>Second Template</h2>
Name: {{mainCtrl.name}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment