1. index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
<!DOCTYPE html>
<html ng-app="fruitApp" lang="en">
<head>
<title>AngularJS directive</title>
<script src='http://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.min.js'></script>
<script src="app.js"></script>
</head>
<body ng-app="fruitApp">
<div ng-controller="fruitController">
<my-example></my-example>
</div>
</body>
</html>
| cs |
2. app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
var app=angular.module('fruitApp', []);
app.controller('fruitController', function($scope) {
$scope.person = {
name: 'Jteve',
address: 'korea'
};
});
app.directive('myExample', function() {
return {
restrict: 'E',
template: 'Name: {{person.name}} </br> Address: {{person.address}}'
};
});
| cs |
3. result
Name: Jteve
Address: korea
Address: korea
4. reference
http://www.nextree.co.kr/p4850/
댓글 없음:
댓글 쓰기