Skip to content

Instantly share code, notes, and snippets.

@thesabbir
Last active October 18, 2015 06:20
Show Gist options
  • Save thesabbir/4d8127beb9837b356980 to your computer and use it in GitHub Desktop.
Save thesabbir/4d8127beb9837b356980 to your computer and use it in GitHub Desktop.
Angular Directive Example
var App = angular.module("App",[]);
App.controller('main',['$scope', function($scope){
$scope.message="Welcome to Tiny App";
$scope.box = { "content" : "This is a Box "};
}]);
App.directive('boxy', function() {
return {
restrict: 'E',
template: '<div class="box">{{box.content}}</div>'
};
});
<!DOCTYPE html>
<html ng-app="App">
<head>
<meta charset="utf-8">
<title>Tiny App</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body ng-controller="main">
{{message}}
<boxy></boxy>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js"></script>
<script src='app.js'></script>
</body>
</html>
.box {
height:100px;
width:100px;
display:block;
background:#aaa;
padding: 30px;
margin: 5px;
text-align: center;
vertical-align: middle;
line-height:100px;
box-shadow:1px 1px 5px #000;
color:#eee;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment