Skip to content

Instantly share code, notes, and snippets.

@tedhagos
Created November 28, 2017 02:30
Show Gist options
  • Select an option

  • Save tedhagos/6c2a8ebbf5d93bdada472d506130a8b8 to your computer and use it in GitHub Desktop.

Select an option

Save tedhagos/6c2a8ebbf5d93bdada472d506130a8b8 to your computer and use it in GitHub Desktop.
Angular Directives Controllers Modules
<html ng-app="app">
<body ng-controller="ctrl">
<my-directive></my-directive>
<author-card></author-card>
<input type="text" ng-model="myinput"><br/>
<button ng-click="clickMe(myinput)"> Click me</button>
{{ greeting }}
<script src="bower_components/angular/angular.js"></script>
<script src="1.js"></script>
</body>
</html>
var mod = angular.module('app',[]);
mod.directive('myDirective', function(){
return {
restrict: 'AEC',
template: "<h1>Hello Directive</h1>"
};
});
mod.directive('authorCard', function() {
return {
restrict: 'E',
templateUrl: 'author-card.html'
}
});
mod.controller('ctrl', function($scope){
$scope.clickMe = function(name) {
$scope.greeting = "Hello " + name;
}
$scope.user = {
lastname: "Gosling",
firstname: "James"
};
$scope.user2 = {
lastname: "Hevery",
firstname: "Misko"
};
$scope.authors = [
{name: 'Victor Hugo', book: 'Les Miserables'},
{name: 'Bjarne Stroustrup', book: 'C++ Programming'},
{name: 'James Gosling', book: 'Java Programming'},
{name: 'Leo Tolstoy', book:'War and Peace'}
];
});
<div>
<ul>
<li ng-repeat="i in authors">
{{i.name }} {{ i.book }}
</li>
</ul>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment