/index.html Secret
Created
October 25, 2015 00:44
Using the ng-include Directive to Process Fragments Dynamically
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html ng-app="exampleApp"> | |
<head> | |
<title>Directives</title> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css"> | |
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js"></script> | |
<script> | |
angular.module("exampleApp", []) | |
.controller("defaultCtrl", function($scope) { | |
$scope.todos = [ | |
{action: "Get groceries", complete: false}, | |
{action: "Call plumber", complete: false}, | |
{action: "Buy running shoes", complete: true}, | |
{action: "Buy flowers", complete: false}, | |
{action: "Call family", complete: false}]; | |
$scope.viewFile = function() { | |
return $scope.showList ? "list.html" : "table.html"; | |
}; | |
}); | |
</script> | |
</head> | |
<body> | |
<div id="todoPanel" class="panel" ng-controller="defaultCtrl"> | |
<h3 class="panel-header">To Do List</h3> | |
<div class="well"> | |
<div class="checkbox"> | |
<label> | |
<input type="checkbox" ng-model="showList"> | |
Use the list view | |
</label> | |
</div> | |
</div> | |
<ng-include src="viewFile()"></ng-include> | |
</div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ol> | |
<li ng-repeat="item in todos"> | |
{{item.action}} | |
<span ng-if="item.complete"> (Done)</span> | |
</li> | |
</ol> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<table class="table"> | |
<thead> | |
<tr> | |
<th>#</th> | |
<th>Action</th> | |
<th>Done</th> | |
</tr> | |
</thead> | |
<tr ng-repeat="item in todos" ng-class="$odd ? 'odd' : 'even'"> | |
<td>{{$index + 1}}</td> | |
<td ng-repeat="prop in item">{{prop}}</td> | |
</tr> | |
</table> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment