-
Notifications
You must be signed in to change notification settings - Fork 0
/
angular-directive-demo1.html
65 lines (65 loc) · 2.39 KB
/
angular-directive-demo1.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>angular-directive-隔离</title>
<script type="text/javascript" src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
</head>
<body ng-app="app">
<div>
<div ng-controller="DemoController">
<h3>Demo</h3>
<student-card stu="guy" on-save="saveEditing()"></student-card>
</div>
</div>
<script type="text/html" id="t1">
<div class="panel">
<h3>student card</h3>
<p>
<span>name:</span>
<input type="text" ng-model="stu.name" ng-change="nameChange()">
</p>
<p>
<span>sexy:</span>
<select ng-model="stu.sexy" ng-change="sexyChange()">
<option value="male">male</option>
<option value="female">female</option>
</select>
</p>
<button type="button" name="button" ng-click="onSave()">Save</button>
</div>
</script>
<script type="text/javascript">
var app = angular.module('app', []);
app.controller('DemoController', ['$scope', function($scope){
$scope.guy = {
name: 'Lucas',
sexy: 'male'
};
$scope.saveEditing = function(){
// $http.post('...')
console.log($scope.guy.name + ' is saving');
console.log($scope.guy);
};
$scope.nameChange = function(){
console.log('name changing');
};
$scope.sexyChange = function(){
console.log('sexy changing');
}
}]);
app.directive('studentCard', function(){
return {
restrict: 'E',
scope: {
stu: '=',
onSave: '&'
}, // 完全隔离
template: function(){
return document.getElementById('t1').innerHTML
}
}
});
</script>
</body>
</html>